| Index: chrome/browser/chromeos/gdata/gdata_file_system.cc
|
| ===================================================================
|
| --- chrome/browser/chromeos/gdata/gdata_file_system.cc (revision 149987)
|
| +++ chrome/browser/chromeos/gdata/gdata_file_system.cc (working copy)
|
| @@ -8,6 +8,7 @@
|
| #include <utility>
|
|
|
| #include "base/bind.h"
|
| +#include "base/command_line.h"
|
| #include "base/file_util.h"
|
| #include "base/json/json_file_value_serializer.h"
|
| #include "base/json/json_reader.h"
|
| @@ -27,6 +28,7 @@
|
| #include "chrome/browser/chromeos/gdata/gdata_util.h"
|
| #include "chrome/browser/prefs/pref_service.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/common/chrome_switches.h"
|
| #include "chrome/common/chrome_notification_types.h"
|
| #include "chrome/common/pref_names.h"
|
| #include "content/public/browser/browser_thread.h"
|
| @@ -45,6 +47,8 @@
|
| FILE_PATH_LITERAL("account_metadata.json");
|
| const FilePath::CharType kFilesystemProtoFile[] =
|
| FILE_PATH_LITERAL("file_system.pb");
|
| +const FilePath::CharType kResourceMetadataDBFile[] =
|
| + FILE_PATH_LITERAL("resource_metadata.db");
|
|
|
| const char kEmptyFilePath[] = "/dev/null";
|
|
|
| @@ -78,28 +82,6 @@
|
| #endif
|
| };
|
|
|
| -// Defines set of parameters sent to callback OnProtoLoaded().
|
| -struct LoadRootFeedParams {
|
| - LoadRootFeedParams(
|
| - FilePath search_file_path,
|
| - bool should_load_from_server,
|
| - const FindEntryCallback& callback)
|
| - : search_file_path(search_file_path),
|
| - should_load_from_server(should_load_from_server),
|
| - load_error(GDATA_FILE_OK),
|
| - callback(callback) {
|
| - }
|
| - ~LoadRootFeedParams() {
|
| - }
|
| -
|
| - FilePath search_file_path;
|
| - bool should_load_from_server;
|
| - std::string proto;
|
| - GDataFileError load_error;
|
| - base::Time last_modified;
|
| - const FindEntryCallback callback;
|
| -};
|
| -
|
| // Returns true if file system is due to be serialized on disk based on it
|
| // |serialized_size| and |last_serialized| timestamp.
|
| bool ShouldSerializeFileSystemNow(size_t serialized_size,
|
| @@ -273,6 +255,11 @@
|
| }
|
| }
|
|
|
| +bool UseLevelDB() {
|
| + return CommandLine::ForCurrentProcess()->HasSwitch(
|
| + switches::kUseLevelDBForGData);
|
| +}
|
| +
|
| // Gets the file size of |local_file|.
|
| void GetLocalFileSizeOnBlockingPool(const FilePath& local_file,
|
| GDataFileError* error,
|
| @@ -994,6 +981,9 @@
|
| const FindEntryCallback& callback) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
|
|
| + DVLOG(1) << "ReloadFeedFromServerIfNeeded local_changestamp="
|
| + << local_changestamp << ", initial_origin=" << initial_origin;
|
| +
|
| // First fetch the latest changestamp to see if there were any new changes
|
| // there at all.
|
| documents_service_->GetAccountMetadata(
|
| @@ -1157,7 +1147,7 @@
|
| }
|
|
|
| // Save file system metadata to disk.
|
| - SaveFileSystemAsProto();
|
| + SaveFileSystem();
|
|
|
| // If we had someone to report this too, then this retrieval was done in a
|
| // context of search... so continue search.
|
| @@ -2981,17 +2971,25 @@
|
| const FindEntryCallback& callback) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
|
|
| - const FilePath path =
|
| - cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append(
|
| - kFilesystemProtoFile);
|
| LoadRootFeedParams* params = new LoadRootFeedParams(search_file_path,
|
| should_load_from_server,
|
| callback);
|
| - BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE,
|
| - base::Bind(&LoadProtoOnBlockingPool, path, params),
|
| - base::Bind(&GDataWapiFeedLoader::OnProtoLoaded,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - base::Owned(params)));
|
| + FilePath path = cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META);
|
| + if (UseLevelDB()) {
|
| + path = path.Append(kResourceMetadataDBFile);
|
| + directory_service_->InitFromDB(path, blocking_task_runner_,
|
| + base::Bind(
|
| + &GDataWapiFeedLoader::ContinueWithInitializedDirectoryService,
|
| + weak_ptr_factory_.GetWeakPtr(),
|
| + base::Owned(params)));
|
| + } else {
|
| + path = path.Append(kFilesystemProtoFile);
|
| + BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE,
|
| + base::Bind(&LoadProtoOnBlockingPool, path, params),
|
| + base::Bind(&GDataWapiFeedLoader::OnProtoLoaded,
|
| + weak_ptr_factory_.GetWeakPtr(),
|
| + base::Owned(params)));
|
| + }
|
| }
|
|
|
| void GDataFileSystem::OnDirectoryChanged(const FilePath& directory_path) {
|
| @@ -3043,7 +3041,6 @@
|
| if (directory_service_->origin() == FROM_SERVER)
|
| return;
|
|
|
| - int local_changestamp = 0;
|
| // Update directory structure only if everything is OK and we haven't yet
|
| // received the feed from the server yet.
|
| if (params->load_error == GDATA_FILE_OK) {
|
| @@ -3051,16 +3048,27 @@
|
| if (directory_service_->ParseFromString(params->proto)) {
|
| directory_service_->set_last_serialized(params->last_modified);
|
| directory_service_->set_serialized_size(params->proto.size());
|
| - local_changestamp = directory_service_->largest_changestamp();
|
| } else {
|
| params->load_error = GDATA_FILE_ERROR_FAILED;
|
| LOG(WARNING) << "Parse of cached proto file failed";
|
| }
|
| }
|
|
|
| + ContinueWithInitializedDirectoryService(params, params->load_error);
|
| +}
|
| +
|
| +void GDataWapiFeedLoader::ContinueWithInitializedDirectoryService(
|
| + LoadRootFeedParams* params,
|
| + GDataFileError error) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| +
|
| + DVLOG(1) << "Time elapsed to load directory service from disk="
|
| + << (base::Time::Now() - params->load_start_time).InMilliseconds()
|
| + << " milliseconds";
|
| +
|
| FindEntryCallback callback = params->callback;
|
| // If we got feed content from cache, try search over it.
|
| - if (params->load_error == GDATA_FILE_OK && !callback.is_null()) {
|
| + if (error == GDATA_FILE_OK && !callback.is_null()) {
|
| // Continue file content search operation if the delegate hasn't terminated
|
| // this search branch already.
|
| directory_service_->FindEntryByPathAndRunSync(params->search_file_path,
|
| @@ -3088,33 +3096,35 @@
|
| // |reported| to the original callback, then we just need to refresh the
|
| // content without continuing search upon operation completion.
|
| ReloadFromServerIfNeeded(initial_origin,
|
| - local_changestamp,
|
| + directory_service_->largest_changestamp(),
|
| params->search_file_path,
|
| callback);
|
| }
|
|
|
| -void GDataWapiFeedLoader::SaveFileSystemAsProto() {
|
| +void GDataWapiFeedLoader::SaveFileSystem() {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
|
|
| - DVLOG(1) << "SaveFileSystemAsProto";
|
| -
|
| if (!ShouldSerializeFileSystemNow(directory_service_->serialized_size(),
|
| directory_service_->last_serialized())) {
|
| return;
|
| }
|
|
|
| - const FilePath path =
|
| - cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append(
|
| - kFilesystemProtoFile);
|
| - scoped_ptr<std::string> serialized_proto(new std::string());
|
| - directory_service_->SerializeToString(serialized_proto.get());
|
| - directory_service_->set_last_serialized(base::Time::Now());
|
| - directory_service_->set_serialized_size(serialized_proto->size());
|
| - PostBlockingPoolSequencedTask(
|
| - FROM_HERE,
|
| - blocking_task_runner_,
|
| - base::Bind(&SaveProtoOnBlockingPool, path,
|
| - base::Passed(serialized_proto.Pass())));
|
| + if (UseLevelDB()) {
|
| + directory_service_->SaveToDB();
|
| + } else {
|
| + const FilePath path =
|
| + cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append(
|
| + kFilesystemProtoFile);
|
| + scoped_ptr<std::string> serialized_proto(new std::string());
|
| + directory_service_->SerializeToString(serialized_proto.get());
|
| + directory_service_->set_last_serialized(base::Time::Now());
|
| + directory_service_->set_serialized_size(serialized_proto->size());
|
| + PostBlockingPoolSequencedTask(
|
| + FROM_HERE,
|
| + blocking_task_runner_,
|
| + base::Bind(&SaveProtoOnBlockingPool, path,
|
| + base::Passed(serialized_proto.Pass())));
|
| + }
|
| }
|
|
|
| void GDataFileSystem::OnFilePathUpdated(const FileOperationCallback& callback,
|
| @@ -3509,10 +3519,11 @@
|
| GDataEntry* entry) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
|
|
| - DVLOG(1) << "Initial load finished";
|
| if (!callback.is_null())
|
| callback.Run(error, entry);
|
|
|
| + DVLOG(1) << "RunAndNotifyInitialLoadFinished";
|
| +
|
| // Notify the observers that root directory has been initialized.
|
| FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
|
| OnInitialLoadFinished());
|
|
|