Index: chrome/browser/chromeos/gdata/gdata_files.h |
=================================================================== |
--- chrome/browser/chromeos/gdata/gdata_files.h (revision 148059) |
+++ chrome/browser/chromeos/gdata/gdata_files.h (working copy) |
@@ -5,6 +5,7 @@ |
#ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
#define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
+#include <leveldb/db.h> |
#include <map> |
#include <string> |
@@ -21,6 +22,10 @@ |
#include "chrome/browser/profiles/profile_keyed_service.h" |
#include "chrome/browser/profiles/profile_keyed_service_factory.h" |
+namespace base { |
+class SequencedTaskRunner; |
+} // namespace base |
+ |
namespace gdata { |
class GDataFile; |
@@ -322,6 +327,7 @@ |
DISALLOW_COPY_AND_ASSIGN(GDataDirectory); |
}; |
+// TODO(achuith,hashimoto,satorux): Move this to a separate file. |
// Class to handle GDataEntry* lookups, add/remove GDataEntry*. |
class GDataDirectoryService { |
public: |
@@ -376,13 +382,33 @@ |
void SerializeToString(std::string* serialized_proto) const; |
bool ParseFromString(const std::string& serialized_proto); |
+ // Restore from and save to database. |
+ void InitFromDB(const FilePath& db_path, |
+ base::SequencedTaskRunner* blocking_task_runner); |
satorux1
2012/07/24 16:30:34
Loading from DB can fail, right? If so, the caller
|
+ void SaveResourceMapToDB(); |
hashimoto
2012/07/24 08:41:51
Where is this method used?
|
+ |
private: |
// A map table of file's resource string to its GDataFile* entry. |
typedef std::map<std::string, GDataEntry*> ResourceMap; |
+ // Map of resource id and serialized GDataEntry. |
+ typedef std::map<std::string, std::string> SerializedMap; |
- scoped_ptr<GDataDirectory> root_; // Stored in the serialized proto. |
+ // Helper functions for restoring from and saving to the database. |
+ void ReadFromDBOnBlockingThread(const FilePath& db_path, |
+ SerializedMap* serialized_resources); |
+ void InitDBOnBlockingThread(const FilePath& db_path); |
+ void InitResourceMapOnUIThread(SerializedMap* serialized_resources); |
+ void SaveSerializedToDBOnBlockingThread( |
+ const SerializedMap& serialized_resources); |
+ |
+ scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
+ |
ResourceMap resource_map_; |
+ scoped_ptr<leveldb::DB> level_db_; |
+ FilePath db_path_; |
+ scoped_ptr<GDataDirectory> root_; // Stored in the serialized proto. |
+ |
base::Time last_serialized_; |
size_t serialized_size_; |
int largest_changestamp_; // Stored in the serialized proto. |