Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
| 7 | 7 |
| 8 #include <leveldb/db.h> | |
| 8 #include <map> | 9 #include <map> |
| 9 #include <string> | 10 #include <string> |
| 10 | 11 |
| 11 #include "base/callback.h" | 12 #include "base/callback.h" |
| 12 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 16 #include "base/platform_file.h" | 17 #include "base/platform_file.h" |
| 17 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
| 18 #include "chrome/browser/chromeos/gdata/gdata_params.h" | 19 #include "chrome/browser/chromeos/gdata/gdata_params.h" |
| 19 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" | 20 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" |
| 20 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" | 21 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" |
| 21 #include "chrome/browser/profiles/profile_keyed_service.h" | 22 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 22 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | 23 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
| 23 | 24 |
| 25 namespace base { | |
| 26 class SequencedTaskRunner; | |
| 27 } // namespace base | |
| 28 | |
| 24 namespace gdata { | 29 namespace gdata { |
| 25 | 30 |
| 26 class GDataFile; | 31 class GDataFile; |
| 27 class GDataDirectory; | 32 class GDataDirectory; |
| 28 class GDataDirectoryService; | 33 class GDataDirectoryService; |
| 29 | 34 |
| 30 class GDataEntryProto; | 35 class GDataEntryProto; |
| 31 class GDataDirectoryProto; | 36 class GDataDirectoryProto; |
| 32 class GDataRootDirectoryProto; | 37 class GDataRootDirectoryProto; |
| 33 class PlatformFileInfoProto; | 38 class PlatformFileInfoProto; |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 // entry instance. | 320 // entry instance. |
| 316 bool RemoveChild(GDataEntry* entry); | 321 bool RemoveChild(GDataEntry* entry); |
| 317 | 322 |
| 318 // Collection of children GDataEntry items. | 323 // Collection of children GDataEntry items. |
| 319 GDataFileCollection child_files_; | 324 GDataFileCollection child_files_; |
| 320 GDataDirectoryCollection child_directories_; | 325 GDataDirectoryCollection child_directories_; |
| 321 | 326 |
| 322 DISALLOW_COPY_AND_ASSIGN(GDataDirectory); | 327 DISALLOW_COPY_AND_ASSIGN(GDataDirectory); |
| 323 }; | 328 }; |
| 324 | 329 |
| 330 // TODO(achuith,hashimoto,satorux): Move this to a separate file. | |
| 325 // Class to handle GDataEntry* lookups, add/remove GDataEntry*. | 331 // Class to handle GDataEntry* lookups, add/remove GDataEntry*. |
| 326 class GDataDirectoryService { | 332 class GDataDirectoryService { |
| 327 public: | 333 public: |
| 328 // Callback for GetEntryByResourceIdAsync. | 334 // Callback for GetEntryByResourceIdAsync. |
| 329 typedef base::Callback<void(GDataEntry* entry)> GetEntryByResourceIdCallback; | 335 typedef base::Callback<void(GDataEntry* entry)> GetEntryByResourceIdCallback; |
| 330 | 336 |
| 331 GDataDirectoryService(); | 337 GDataDirectoryService(); |
| 332 ~GDataDirectoryService(); | 338 ~GDataDirectoryService(); |
| 333 | 339 |
| 334 GDataDirectory* root() { return root_.get(); } | 340 GDataDirectory* root() { return root_.get(); } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 const GetEntryByResourceIdCallback& callback); | 375 const GetEntryByResourceIdCallback& callback); |
| 370 | 376 |
| 371 // Replaces file entry with the same resource id as |fresh_file| with its | 377 // Replaces file entry with the same resource id as |fresh_file| with its |
| 372 // fresh value |fresh_file|. | 378 // fresh value |fresh_file|. |
| 373 void RefreshFile(scoped_ptr<GDataFile> fresh_file); | 379 void RefreshFile(scoped_ptr<GDataFile> fresh_file); |
| 374 | 380 |
| 375 // Serializes/Parses to/from string via proto classes. | 381 // Serializes/Parses to/from string via proto classes. |
| 376 void SerializeToString(std::string* serialized_proto) const; | 382 void SerializeToString(std::string* serialized_proto) const; |
| 377 bool ParseFromString(const std::string& serialized_proto); | 383 bool ParseFromString(const std::string& serialized_proto); |
| 378 | 384 |
| 385 // Restore from and save to database. | |
| 386 void InitFromDB(const FilePath& db_path, | |
| 387 base::SequencedTaskRunner* blocking_task_runner); | |
|
satorux1
2012/07/24 16:30:34
Loading from DB can fail, right? If so, the caller
| |
| 388 void SaveResourceMapToDB(); | |
|
hashimoto
2012/07/24 08:41:51
Where is this method used?
| |
| 389 | |
| 379 private: | 390 private: |
| 380 // A map table of file's resource string to its GDataFile* entry. | 391 // A map table of file's resource string to its GDataFile* entry. |
| 381 typedef std::map<std::string, GDataEntry*> ResourceMap; | 392 typedef std::map<std::string, GDataEntry*> ResourceMap; |
| 393 // Map of resource id and serialized GDataEntry. | |
| 394 typedef std::map<std::string, std::string> SerializedMap; | |
| 395 | |
| 396 // Helper functions for restoring from and saving to the database. | |
| 397 void ReadFromDBOnBlockingThread(const FilePath& db_path, | |
| 398 SerializedMap* serialized_resources); | |
| 399 void InitDBOnBlockingThread(const FilePath& db_path); | |
| 400 void InitResourceMapOnUIThread(SerializedMap* serialized_resources); | |
| 401 void SaveSerializedToDBOnBlockingThread( | |
| 402 const SerializedMap& serialized_resources); | |
| 403 | |
| 404 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | |
| 405 | |
| 406 ResourceMap resource_map_; | |
| 407 scoped_ptr<leveldb::DB> level_db_; | |
| 408 FilePath db_path_; | |
| 382 | 409 |
| 383 scoped_ptr<GDataDirectory> root_; // Stored in the serialized proto. | 410 scoped_ptr<GDataDirectory> root_; // Stored in the serialized proto. |
| 384 ResourceMap resource_map_; | |
| 385 | 411 |
| 386 base::Time last_serialized_; | 412 base::Time last_serialized_; |
| 387 size_t serialized_size_; | 413 size_t serialized_size_; |
| 388 int largest_changestamp_; // Stored in the serialized proto. | 414 int largest_changestamp_; // Stored in the serialized proto. |
| 389 ContentOrigin origin_; | 415 ContentOrigin origin_; |
| 390 | 416 |
| 391 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); | 417 DISALLOW_COPY_AND_ASSIGN(GDataDirectoryService); |
| 392 }; | 418 }; |
| 393 | 419 |
| 394 } // namespace gdata | 420 } // namespace gdata |
| 395 | 421 |
| 396 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ | 422 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_FILES_H_ |
| OLD | NEW |