diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-11 04:50:08 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-11 04:50:08 +0000 |
commit | 1cc8f1e0137d469c18cda277593f429761d0c647 (patch) | |
tree | 398a8e16402caaa1222e7cea170217f473cd714e | |
parent | 734ccb90f2c49684d9cab5e857596562b7b569ab (diff) | |
download | chromium_src-1cc8f1e0137d469c18cda277593f429761d0c647.zip chromium_src-1cc8f1e0137d469c18cda277593f429761d0c647.tar.gz chromium_src-1cc8f1e0137d469c18cda277593f429761d0c647.tar.bz2 |
Delete gdata::FindEntryDelegate
Replace all FindEntryDelegate subclasses with ReadOnlyFindEntryCallback and FindEntryCallback
Move FindEntryCallback to find_entry_callback.h
BUG=127028
TEST=unit_tests --gtest_filter="GData*"
Review URL: https://chromiumcodereview.appspot.com/10310077
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136508 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/gdata/find_entry_callback.cc | 17 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/find_entry_callback.h | 33 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/find_entry_delegate.cc | 41 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/find_entry_delegate.h | 76 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_file_system.cc | 22 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_file_system.h | 13 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc | 15 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_files.cc | 38 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_files.h | 6 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_protocol_handler.cc | 57 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_util.cc | 31 | ||||
-rw-r--r-- | chrome/browser/chromeos/gdata/mock_gdata_file_system.h | 5 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 4 |
13 files changed, 126 insertions, 232 deletions
diff --git a/chrome/browser/chromeos/gdata/find_entry_callback.cc b/chrome/browser/chromeos/gdata/find_entry_callback.cc new file mode 100644 index 0000000..2edd47d --- /dev/null +++ b/chrome/browser/chromeos/gdata/find_entry_callback.cc @@ -0,0 +1,17 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/gdata/find_entry_callback.h" + +namespace gdata { + +void ReadOnlyFindEntryCallback(GDataEntry** out, + base::PlatformFileError error, + const FilePath& directory_path, + GDataEntry* entry) { + if (error == base::PLATFORM_FILE_OK) + *out = entry; +} + +} // namespace gdata diff --git a/chrome/browser/chromeos/gdata/find_entry_callback.h b/chrome/browser/chromeos/gdata/find_entry_callback.h new file mode 100644 index 0000000..f0e344c --- /dev/null +++ b/chrome/browser/chromeos/gdata/find_entry_callback.h @@ -0,0 +1,33 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_GDATA_FIND_ENTRY_CALLBACK_H_ +#define CHROME_BROWSER_CHROMEOS_GDATA_FIND_ENTRY_CALLBACK_H_ +#pragma once + +#include "base/callback.h" +#include "base/platform_file.h" + +namespace gdata { + +class GDataEntry; + +// Used to get result of file search. Please note that |file| is a live +// object provided to this callback under lock. It must not be used outside +// of the callback method. This callback can be invoked on different thread +// than one that started the request. +typedef base::Callback<void(base::PlatformFileError error, + const FilePath& directory_path, + GDataEntry* entry)> + FindEntryCallback; + +// Callback used to find a directory element for file system updates. +void ReadOnlyFindEntryCallback(GDataEntry** out, + base::PlatformFileError error, + const FilePath& directory_path, + GDataEntry* entry); + +} // namespace gdata + +#endif // CHROME_BROWSER_CHROMEOS_GDATA_FIND_ENTRY_CALLBACK_H_ diff --git a/chrome/browser/chromeos/gdata/find_entry_delegate.cc b/chrome/browser/chromeos/gdata/find_entry_delegate.cc deleted file mode 100644 index f91e3d1..0000000 --- a/chrome/browser/chromeos/gdata/find_entry_delegate.cc +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/chromeos/gdata/find_entry_delegate.h" - -#include "chrome/browser/chromeos/gdata/gdata_files.h" - -namespace gdata { - -FindEntryDelegate::~FindEntryDelegate() { -} - -ReadOnlyFindEntryDelegate::ReadOnlyFindEntryDelegate() : entry_(NULL) { -} - -void ReadOnlyFindEntryDelegate::OnDone(base::PlatformFileError error, - const FilePath& directory_path, - GDataEntry* entry) { - DCHECK(!entry_); - if (error == base::PLATFORM_FILE_OK) - entry_ = entry; - else - entry_ = NULL; -} - -FindEntryCallbackRelayDelegate::FindEntryCallbackRelayDelegate( - const FindEntryCallback& callback) : callback_(callback) { -} - -FindEntryCallbackRelayDelegate::~FindEntryCallbackRelayDelegate() { -} - -void FindEntryCallbackRelayDelegate::OnDone(base::PlatformFileError error, - const FilePath& directory_path, - GDataEntry* entry) { - if (!callback_.is_null()) - callback_.Run(error, directory_path, entry); -} - -} // namespace gdata diff --git a/chrome/browser/chromeos/gdata/find_entry_delegate.h b/chrome/browser/chromeos/gdata/find_entry_delegate.h deleted file mode 100644 index e5f3e23..0000000 --- a/chrome/browser/chromeos/gdata/find_entry_delegate.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROMEOS_GDATA_FIND_ENTRY_DELEGATE_H_ -#define CHROME_BROWSER_CHROMEOS_GDATA_FIND_ENTRY_DELEGATE_H_ -#pragma once - -#include "base/bind.h" -#include "base/platform_file.h" - -class FilePath; - -namespace gdata { - -class GDataEntry; - -// Used to get result of file search. Please note that |file| is a live -// object provided to this callback under lock. It must not be used outside -// of the callback method. This callback can be invoked on different thread -// than one that started the request. -typedef base::Callback<void(base::PlatformFileError error, - const FilePath& directory_path, - GDataEntry* entry)> - FindEntryCallback; - -// Delegate class used to deal with results synchronous read-only search -// over virtual file system. -class FindEntryDelegate { - public: - virtual ~FindEntryDelegate(); - - // Called when GDataRootDirectory::FindEntryByPath() completes search. - virtual void OnDone(base::PlatformFileError error, - const FilePath& directory_path, - GDataEntry* entry) = 0; -}; - -// Delegate used to find a directory element for file system updates. -class ReadOnlyFindEntryDelegate : public FindEntryDelegate { - public: - ReadOnlyFindEntryDelegate(); - - // Returns found entry. - GDataEntry* entry() { return entry_; } - - private: - // FindEntryDelegate overrides. - virtual void OnDone(base::PlatformFileError error, - const FilePath& directory_path, - GDataEntry* entry) OVERRIDE; - - // Entry that was found. - GDataEntry* entry_; -}; - -// FindEntryCallbackRelayDelegate class implementation. -// This class is used to relay calls between sync and async versions -// of FindFileByPath(Sync|Async) calls. -class FindEntryCallbackRelayDelegate : public FindEntryDelegate { - public: - explicit FindEntryCallbackRelayDelegate(const FindEntryCallback& callback); - virtual ~FindEntryCallbackRelayDelegate(); - - private: - // FindEntryDelegate overrides. - virtual void OnDone(base::PlatformFileError error, - const FilePath& directory_path, - GDataEntry* entry) OVERRIDE; - - const FindEntryCallback callback_; -}; - -} // namespace gdata - -#endif // CHROME_BROWSER_CHROMEOS_GDATA_FIND_ENTRY_DELEGATE_H_ diff --git a/chrome/browser/chromeos/gdata/gdata_file_system.cc b/chrome/browser/chromeos/gdata/gdata_file_system.cc index b1c9a91..d329e9e 100644 --- a/chrome/browser/chromeos/gdata/gdata_file_system.cc +++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc @@ -1108,7 +1108,7 @@ void GDataFileSystem::Authenticate(const AuthStatusCallback& callback) { void GDataFileSystem::FindEntryByResourceIdSync( const std::string& resource_id, - FindEntryDelegate* delegate) { + const FindEntryCallback& callback) { base::AutoLock lock(lock_); // To access the cache map. GDataFile* file = NULL; @@ -1116,12 +1116,10 @@ void GDataFileSystem::FindEntryByResourceIdSync( if (entry) file = entry->AsGDataFile(); - if (file) { - delegate->OnDone(base::PLATFORM_FILE_OK, file->parent()->GetFilePath(), - file); - } else { - delegate->OnDone(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); - } + if (file) + callback.Run(base::PLATFORM_FILE_OK, file->parent()->GetFilePath(), file); + else + callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); } void GDataFileSystem::FindEntryByPathAsyncOnUIThread( @@ -1167,8 +1165,7 @@ void GDataFileSystem::FindEntryByPathSyncOnUIThread( DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); base::AutoLock lock(lock_); // To access root_. - FindEntryCallbackRelayDelegate delegate(callback); - root_->FindEntryByPath(search_file_path, &delegate); + root_->FindEntryByPath(search_file_path, callback); } void GDataFileSystem::ReloadFeedFromServerIfNeeded( @@ -2566,9 +2563,10 @@ GDataEntry* GDataFileSystem::GetGDataEntryByPath( const FilePath& file_path) { lock_.AssertAcquired(); // Find directory element within the cached file system snapshot. - ReadOnlyFindEntryDelegate find_delegate; - root_->FindEntryByPath(file_path, &find_delegate); - return find_delegate.entry(); + GDataEntry* entry = NULL; + root_->FindEntryByPath(file_path, base::Bind(&ReadOnlyFindEntryCallback, + &entry)); + return entry; } void GDataFileSystem::GetCacheState(const std::string& resource_id, diff --git a/chrome/browser/chromeos/gdata/gdata_file_system.h b/chrome/browser/chromeos/gdata/gdata_file_system.h index 28f481f..d9370ae 100644 --- a/chrome/browser/chromeos/gdata/gdata_file_system.h +++ b/chrome/browser/chromeos/gdata/gdata_file_system.h @@ -21,7 +21,7 @@ #include "base/timer.h" #include "base/synchronization/lock.h" #include "base/threading/sequenced_worker_pool.h" -#include "chrome/browser/chromeos/gdata/find_entry_delegate.h" +#include "chrome/browser/chromeos/gdata/find_entry_callback.h" #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" #include "chrome/browser/chromeos/gdata/gdata_files.h" #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" @@ -210,13 +210,13 @@ class GDataFileSystemInterface { virtual void Authenticate(const AuthStatusCallback& callback) = 0; // Finds file info by using |resource_id|. This call does not initiate - // content refreshing and will invoke one of |delegate| methods directly as + // content refreshing and will invoke one of |callback| methods directly as // it executes. // - // Can be called from UI/IO thread. |delegate| is run on the calling thread + // Can be called from UI/IO thread. |callback| is run on the calling thread // synchronously. virtual void FindEntryByResourceIdSync(const std::string& resource_id, - FindEntryDelegate* delegate) = 0; + const FindEntryCallback& callback) = 0; // Initiates transfer of |remote_src_file_path| to |local_dest_file_path|. // |remote_src_file_path| is the virtual source path on the gdata file system. @@ -437,8 +437,9 @@ class GDataFileSystem : public GDataFileSystemInterface, virtual void StopUpdates() OVERRIDE; virtual void CheckForUpdates() OVERRIDE; virtual void Authenticate(const AuthStatusCallback& callback) OVERRIDE; - virtual void FindEntryByResourceIdSync(const std::string& resource_id, - FindEntryDelegate* delegate) OVERRIDE; + virtual void FindEntryByResourceIdSync( + const std::string& resource_id, + const FindEntryCallback& callback) OVERRIDE; virtual void SearchAsync(const std::string& search_query, const ReadDirectoryCallback& callback) OVERRIDE; virtual void TransferFileFromRemoteToLocal( diff --git a/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc b/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc index 66915ac..0efffbf 100644 --- a/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc +++ b/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc @@ -292,9 +292,10 @@ class GDataFileSystemTest : public testing::Test { } GDataEntry* FindEntry(const FilePath& file_path) { - ReadOnlyFindEntryDelegate search_delegate; - file_system_->root_->FindEntryByPath(file_path, &search_delegate); - return search_delegate.entry(); + GDataEntry* entry = NULL; + file_system_->root_->FindEntryByPath( + file_path, base::Bind(&ReadOnlyFindEntryCallback, &entry)); + return entry; } void FindAndTestFilePath(const FilePath& file_path) { @@ -304,10 +305,10 @@ class GDataFileSystemTest : public testing::Test { } GDataEntry* FindEntryByResourceId(const std::string& resource_id) { - ReadOnlyFindEntryDelegate search_delegate; - file_system_->FindEntryByResourceIdSync(resource_id, - &search_delegate); - return search_delegate.entry(); + GDataEntry* entry = NULL; + file_system_->FindEntryByResourceIdSync( + resource_id, base::Bind(&ReadOnlyFindEntryCallback, &entry)); + return entry; } // Gets the entry info for |file_path| and compares the contents against diff --git a/chrome/browser/chromeos/gdata/gdata_files.cc b/chrome/browser/chromeos/gdata/gdata_files.cc index 83182bb..a1350d8 100644 --- a/chrome/browser/chromeos/gdata/gdata_files.cc +++ b/chrome/browser/chromeos/gdata/gdata_files.cc @@ -8,7 +8,6 @@ #include "base/platform_file.h" #include "base/stringprintf.h" #include "base/string_util.h" -#include "chrome/browser/chromeos/gdata/find_entry_delegate.h" #include "chrome/browser/chromeos/gdata/gdata.pb.h" #include "chrome/browser/chromeos/gdata/gdata_parser.h" #include "chrome/browser/chromeos/gdata/gdata_util.h" @@ -504,11 +503,10 @@ bool GDataRootDirectory::ModifyFindEntryParamsForSearchPath( return true; } -void GDataRootDirectory::FindEntryByPath( - const FilePath& file_path, - FindEntryDelegate* delegate) { +void GDataRootDirectory::FindEntryByPath(const FilePath& file_path, + const FindEntryCallback& callback) { // GDataFileSystem has already locked. - DCHECK(delegate); + DCHECK(!callback.is_null()); std::vector<FilePath::StringType> components; file_path.GetComponents(&components); @@ -521,8 +519,8 @@ void GDataRootDirectory::FindEntryByPath( if (path_type == util::GDATA_SEARCH_PATH_ROOT || path_type == util::GDATA_SEARCH_PATH_QUERY) { - delegate->OnDone(base::PLATFORM_FILE_OK, file_path.DirName(), - fake_search_directory_.get()); + callback.Run(base::PLATFORM_FILE_OK, file_path.DirName(), + fake_search_directory_.get()); return; } @@ -531,7 +529,7 @@ void GDataRootDirectory::FindEntryByPath( if (path_type != util::GDATA_SEARCH_PATH_INVALID) { if (!ModifyFindEntryParamsForSearchPath(file_path, &components, ¤t_dir, &directory_path)) { - delegate->OnDone(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); + callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); return; } } @@ -541,18 +539,17 @@ void GDataRootDirectory::FindEntryByPath( // Last element must match, if not last then it must be a directory. if (i == components.size() - 1) { - if (current_dir->file_name() == components[i]) { - delegate->OnDone(base::PLATFORM_FILE_OK, directory_path, current_dir); - } else { - delegate->OnDone(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); - } + if (current_dir->file_name() == components[i]) + callback.Run(base::PLATFORM_FILE_OK, directory_path, current_dir); + else + callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); return; } // Not the last part of the path, search for the next segment. GDataEntry* entry = current_dir->FindChild(components[i + 1]); if (!entry) { - delegate->OnDone(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); + callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); return; } @@ -561,18 +558,15 @@ void GDataRootDirectory::FindEntryByPath( // Found directory, continue traversal. current_dir = entry->AsGDataDirectory(); } else { - if ((i + 1) == (components.size() - 1)) { - delegate->OnDone(base::PLATFORM_FILE_OK, - directory_path, - entry); - } else { - delegate->OnDone(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); - } + if ((i + 1) == (components.size() - 1)) + callback.Run(base::PLATFORM_FILE_OK, directory_path, entry); + else + callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); return; } } - delegate->OnDone(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); + callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, FilePath(), NULL); } GDataEntry* GDataRootDirectory::GetEntryByResourceId( diff --git a/chrome/browser/chromeos/gdata/gdata_files.h b/chrome/browser/chromeos/gdata/gdata_files.h index 51e9660..6b7e01d 100644 --- a/chrome/browser/chromeos/gdata/gdata_files.h +++ b/chrome/browser/chromeos/gdata/gdata_files.h @@ -17,6 +17,7 @@ #include "base/memory/weak_ptr.h" #include "base/platform_file.h" #include "base/synchronization/lock.h" +#include "chrome/browser/chromeos/gdata/find_entry_callback.h" #include "chrome/browser/chromeos/gdata/gdata_params.h" #include "chrome/browser/chromeos/gdata/gdata_parser.h" #include "chrome/browser/chromeos/gdata/gdata_uploader.h" @@ -25,7 +26,6 @@ namespace gdata { -class FindEntryDelegate; class GDataFile; class GDataDirectory; class GDataRootDirectory; @@ -460,9 +460,9 @@ class GDataRootDirectory : public GDataDirectory { // Removes the entry from resource map. void RemoveEntryFromResourceMap(GDataEntry* entry); - // Searches for |file_path| triggering callback in |delegate|. + // Searches for |file_path| triggering callback. void FindEntryByPath(const FilePath& file_path, - FindEntryDelegate* delegate); + const FindEntryCallback& callback); // Returns the GDataEntry* with the corresponding |resource_id|. GDataEntry* GetEntryByResourceId(const std::string& resource_id); diff --git a/chrome/browser/chromeos/gdata/gdata_protocol_handler.cc b/chrome/browser/chromeos/gdata/gdata_protocol_handler.cc index 97f16a7..99019c6 100644 --- a/chrome/browser/chromeos/gdata/gdata_protocol_handler.cc +++ b/chrome/browser/chromeos/gdata/gdata_protocol_handler.cc @@ -99,36 +99,6 @@ void CancelGDataDownloadOnUIThread(const FilePath& gdata_file_path) { file_system->GetOperationRegistry()->CancelForFilePath(gdata_file_path); } -// Class delegate to find file by resource id and extract relevant file info. -class GetFileInfoDelegate : public gdata::FindEntryDelegate { - public: - GetFileInfoDelegate() : initial_file_size_(0) {} - virtual ~GetFileInfoDelegate() {} - - const std::string& mime_type() const { return mime_type_; } - const std::string& file_name() const { return file_name_; } - const FilePath& gdata_file_path() const { return gdata_file_path_; } - int64 initial_file_size() const { return initial_file_size_; } - - private: - // GDataFileSystem::FindEntryDelegate overrides. - virtual void OnDone(base::PlatformFileError error, - const FilePath& directory_path, - gdata::GDataEntry* entry) OVERRIDE { - if (error == base::PLATFORM_FILE_OK && entry && entry->AsGDataFile()) { - mime_type_ = entry->AsGDataFile()->content_mime_type(); - file_name_ = entry->AsGDataFile()->file_name(); - gdata_file_path_= entry->GetFilePath(); - initial_file_size_ = entry->file_info().size; - } - } - - std::string mime_type_; - std::string file_name_; - FilePath gdata_file_path_; - int64 initial_file_size_; -}; - // GDataURLRequesetJob is the gateway between network-level drive://... // requests for gdata resources and GDataFileSytem. It exposes content URLs // formatted as drive://<resource-id>. @@ -355,9 +325,12 @@ bool GDataURLRequestJob::GetMimeType(std::string* mime_type) const { return false; } - GetFileInfoDelegate delegate; - file_system_->FindEntryByResourceIdSync(resource_id, &delegate); - mime_type->assign(delegate.mime_type()); + GDataEntry* entry = NULL; + file_system_->FindEntryByResourceIdSync( + resource_id, base::Bind(&ReadOnlyFindEntryCallback, &entry)); + if (!entry || !entry->AsGDataFile()) + return false; + mime_type->assign(entry->AsGDataFile()->content_mime_type()); return !mime_type->empty(); } @@ -507,12 +480,18 @@ void GDataURLRequestJob::StartAsync(GDataFileSystem** file_system) { } // First, check if file metadata is matching our expectations. - GetFileInfoDelegate delegate; - file_system_->FindEntryByResourceIdSync(resource_id, &delegate); - - mime_type_ = delegate.mime_type(); - gdata_file_path_ = delegate.gdata_file_path(); - initial_file_size_ = delegate.initial_file_size(); + GDataEntry* entry = NULL; + file_system_->FindEntryByResourceIdSync( + resource_id, base::Bind(&ReadOnlyFindEntryCallback, &entry)); + if (entry && entry->AsGDataFile()) { + mime_type_ = entry->AsGDataFile()->content_mime_type(); + gdata_file_path_ = entry->GetFilePath(); + initial_file_size_ = entry->file_info().size; + } else { + mime_type_.clear(); + gdata_file_path_.clear(); + initial_file_size_ = 0; + } remaining_bytes_ = initial_file_size_; DVLOG(1) << "Getting file for resource id"; diff --git a/chrome/browser/chromeos/gdata/gdata_util.cc b/chrome/browser/chromeos/gdata/gdata_util.cc index d06b14e..7b755b3 100644 --- a/chrome/browser/chromeos/gdata/gdata_util.cc +++ b/chrome/browser/chromeos/gdata/gdata_util.cc @@ -56,25 +56,6 @@ const int kReadOnlyFilePermissions = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_EXCLUSIVE_READ | base::PLATFORM_FILE_ASYNC; -class GetFileNameDelegate : public FindEntryDelegate { - public: - GetFileNameDelegate() {} - virtual ~GetFileNameDelegate() {} - - const std::string& file_name() const { return file_name_; } - private: - // GDataFileSystem::FindEntryDelegate overrides. - virtual void OnDone(base::PlatformFileError error, - const FilePath& directory_path, - GDataEntry* entry) OVERRIDE { - if (error == base::PLATFORM_FILE_OK && entry && entry->AsGDataFile()) { - file_name_ = entry->AsGDataFile()->file_name(); - } - } - - std::string file_name_; -}; - GDataFileSystem* GetGDataFileSystem(Profile* profile) { GDataSystemService* system_service = GDataSystemServiceFactory::GetForProfile(profile); @@ -167,9 +148,15 @@ void ModifyGDataFileResourceUrl(Profile* profile, GDataRootDirectory::CACHE_TYPE_TMP).IsParent(gdata_cache_path)) { const std::string resource_id = gdata_cache_path.BaseName().RemoveExtension().AsUTF8Unsafe(); - GetFileNameDelegate delegate; - file_system->FindEntryByResourceIdSync(resource_id, &delegate); - *url = gdata::util::GetFileResourceUrl(resource_id, delegate.file_name()); + GDataEntry* entry = NULL; + file_system->FindEntryByResourceIdSync( + resource_id, base::Bind(&ReadOnlyFindEntryCallback, &entry)); + + std::string file_name; + if (entry && entry->AsGDataFile()) + file_name = entry->AsGDataFile()->file_name(); + + *url = gdata::util::GetFileResourceUrl(resource_id, file_name); DVLOG(1) << "ModifyGDataFileResourceUrl " << *url; } } diff --git a/chrome/browser/chromeos/gdata/mock_gdata_file_system.h b/chrome/browser/chromeos/gdata/mock_gdata_file_system.h index abcbb36..d52845d 100644 --- a/chrome/browser/chromeos/gdata/mock_gdata_file_system.h +++ b/chrome/browser/chromeos/gdata/mock_gdata_file_system.h @@ -25,8 +25,9 @@ class MockGDataFileSystem : public GDataFileSystemInterface { MOCK_METHOD0(StopUpdates, void()); MOCK_METHOD0(CheckForUpdates, void()); MOCK_METHOD1(Authenticate, void(const AuthStatusCallback& callback)); - MOCK_METHOD2(FindEntryByResourceIdSync, void(const std::string& resource_id, - FindEntryDelegate* delegate)); + MOCK_METHOD2(FindEntryByResourceIdSync, + void(const std::string& resource_id, + const FindEntryCallback& callback)); MOCK_METHOD2(SearchAsync, void(const std::string& search_query, const ReadDirectoryCallback& callback)); MOCK_METHOD3(TransferFileFromRemoteToLocal, diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index ac56455..40ecf54 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -509,8 +509,8 @@ 'browser/chromeos/external_protocol_dialog.h', 'browser/chromeos/gdata/drive_webapps_registry.cc', 'browser/chromeos/gdata/drive_webapps_registry.h', - 'browser/chromeos/gdata/find_entry_delegate.cc', - 'browser/chromeos/gdata/find_entry_delegate.h', + 'browser/chromeos/gdata/find_entry_callback.cc', + 'browser/chromeos/gdata/find_entry_callback.h', 'browser/chromeos/gdata/gdata_auth_service.cc', 'browser/chromeos/gdata/gdata_auth_service.h', 'browser/chromeos/gdata/gdata_db.h', |