1

I want to collect information on how user uses my extension. What I am thinking is i am going to write the information(time,data collected) whenever user interacts with my extension to a local file within the profile folder. And I will send that file to the server periodically.

Is this is a correct way of doing what I am trying? Is this going to produce any performance degradation?

Is there any better way of doing this?

Selvaraj M A
  • 3,096
  • 3
  • 30
  • 46

2 Answers2

3

What you have to consider: disk I/O can take non-negligible amounts of time, e.g. if the disk is busy or if the user's profile is located on a network location. So the obvious approach to open a file, write a line of data into it and close the file again would indeed degrade performance because the browser UI is blocked while you are writing into the file. Your options are:

  • Open the file once and use nsIBufferedOutputStream with a sufficiently large buffer. This will have the effect that only few of your write operations will trigger a write to disk. Downsides: you still have synchronous write operations every now and then, and if the browser crashes the buffer contents will not be written out to disk - your file gets corrupted.
  • Use NetUtil.asyncCopy() to write data asynchronously, without blocking everything. The code example in the documentation shows how one would write a string using nsIStringInputStream. Downside: this is probably not terribly efficient memory-wise, a number of XPCOM objects needs to be created for each write operation.
  • Use an SQLite database, it gives you asynchronous API and ensures consistency even if the browser crashes. If you open the database connection only once and then write into it every now and then it should be more efficient than the solution above (but I didn't test). Downside: your result is a database file rather than a plain text file, you either have to convert it before sending to the server or the server needs to process an SQLite database (which might be more complicated than reading a text file).
Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
1

I see nothing wrong with that attitude, definitely better than sending it notoriously in small chunks.

However you should write it very clearly that you want to send that data (and perhaps display a new tab with some information after user installs the add-on), because some users don't quite like to be spied.

You can send data with XMLHttpRequest (see here).

Community
  • 1
  • 1
jakub.g
  • 38,512
  • 12
  • 92
  • 130