diff options
author | mtomasz@chromium.org <mtomasz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-10 04:48:01 +0000 |
---|---|---|
committer | mtomasz@chromium.org <mtomasz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-10 04:48:01 +0000 |
commit | a0927550607ce907dd4733ff94d9671d0598d7ec (patch) | |
tree | 872366d34a48eaca042e61e31272e3abba489f06 /chrome/browser | |
parent | 11387d28032c36724cfe108c544b639c33a6109a (diff) | |
download | chromium_src-a0927550607ce907dd4733ff94d9671d0598d7ec.zip chromium_src-a0927550607ce907dd4733ff94d9671d0598d7ec.tar.gz chromium_src-a0927550607ce907dd4733ff94d9671d0598d7ec.tar.bz2 |
Externalized observer classes in gdata files.
Formerly nested observer classes are now refactored to top-level classes in separate files. Therefore, now to implement an observer we need to include only the *_observer.h file.
OperationRegistryObserver has not been moved to separate file because it uses another nested structures.
Also, redundant includes were removed and changed into required forward declarations.
BUG=141261
TEST=unit_tests
Review URL: https://chromiumcodereview.appspot.com/10914191
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161044 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
30 files changed, 296 insertions, 163 deletions
diff --git a/chrome/browser/chromeos/extensions/file_browser_event_router.cc b/chrome/browser/chromeos/extensions/file_browser_event_router.cc index 19d5e22..8aebd70 100644 --- a/chrome/browser/chromeos/extensions/file_browser_event_router.cc +++ b/chrome/browser/chromeos/extensions/file_browser_event_router.cc @@ -13,6 +13,7 @@ #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/extensions/file_browser_notifications.h" #include "chrome/browser/chromeos/extensions/file_manager_util.h" +#include "chrome/browser/chromeos/gdata/drive_file_system_interface.h" #include "chrome/browser/chromeos/gdata/drive_file_system_util.h" #include "chrome/browser/chromeos/gdata/drive_service_interface.h" #include "chrome/browser/chromeos/gdata/drive_system_service.h" diff --git a/chrome/browser/chromeos/extensions/file_browser_event_router.h b/chrome/browser/chromeos/extensions/file_browser_event_router.h index 57073a1..b51caaf 100644 --- a/chrome/browser/chromeos/extensions/file_browser_event_router.h +++ b/chrome/browser/chromeos/extensions/file_browser_event_router.h @@ -15,8 +15,10 @@ #include "base/string16.h" #include "base/synchronization/lock.h" #include "chrome/browser/chromeos/cros/network_library.h" -#include "chrome/browser/chromeos/gdata/drive_file_system_interface.h" +#include "chrome/browser/chromeos/gdata/drive_file_system_observer.h" +#include "chrome/browser/chromeos/gdata/drive_resource_metadata.h" #include "chrome/browser/chromeos/gdata/drive_service_interface.h" +#include "chrome/browser/google_apis/operation_registry.h" #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" #include "chrome/browser/profiles/refcounted_profile_keyed_service_factory.h" #include "chromeos/disks/disk_mount_manager.h" @@ -28,6 +30,11 @@ class FileBrowserNotifications; class PrefChangeRegistrar; class Profile; +namespace gdata { +class DriveEntryProto; +class DriveFileSystemInterface; +} + // Monitors changes in disk mounts, network connection state and preferences // affecting File Manager. Dispatches appropriate File Browser events. class FileBrowserEventRouter @@ -35,8 +42,8 @@ class FileBrowserEventRouter public chromeos::disks::DiskMountManager::Observer, public chromeos::NetworkLibrary::NetworkManagerObserver, public content::NotificationObserver, - public gdata::DriveServiceObserver, - public gdata::DriveFileSystemInterface::Observer { + public gdata::DriveFileSystemObserver, + public gdata::DriveServiceObserver { public: // RefcountedProfileKeyedService overrides. virtual void ShutdownOnUIThread() OVERRIDE; diff --git a/chrome/browser/chromeos/extensions/file_browser_private_api.cc b/chrome/browser/chromeos/extensions/file_browser_private_api.cc index 9621e4f..dfc56b3 100644 --- a/chrome/browser/chromeos/extensions/file_browser_private_api.cc +++ b/chrome/browser/chromeos/extensions/file_browser_private_api.cc @@ -26,6 +26,7 @@ #include "chrome/browser/chromeos/extensions/file_handler_util.h" #include "chrome/browser/chromeos/extensions/file_manager_util.h" #include "chrome/browser/chromeos/gdata/drive.pb.h" +#include "chrome/browser/chromeos/gdata/drive_file_system_interface.h" #include "chrome/browser/chromeos/gdata/drive_file_system_util.h" #include "chrome/browser/chromeos/gdata/drive_service_interface.h" #include "chrome/browser/chromeos/gdata/drive_system_service.h" diff --git a/chrome/browser/chromeos/gdata/drive_api_service.h b/chrome/browser/chromeos/gdata/drive_api_service.h index ecc7bd8..bf30702 100644 --- a/chrome/browser/chromeos/gdata/drive_api_service.h +++ b/chrome/browser/chromeos/gdata/drive_api_service.h @@ -11,6 +11,7 @@ #include "base/memory/scoped_ptr.h" #include "chrome/browser/chromeos/gdata/drive_service_interface.h" #include "chrome/browser/google_apis/auth_service.h" +#include "chrome/browser/google_apis/auth_service_observer.h" #include "chrome/browser/google_apis/gdata_operations.h" class FilePath; @@ -25,8 +26,8 @@ class OperationRunner; // Details of API call are abstracted in each operation class and this class // works as a thin wrapper for the API. class DriveAPIService : public DriveServiceInterface, - public AuthService::Observer, - public OperationRegistry::Observer { + public AuthServiceObserver, + public OperationRegistryObserver { public: // Instance is usually created by DriveSystemServiceFactory and owned by // DriveFileSystem. diff --git a/chrome/browser/chromeos/gdata/drive_cache.cc b/chrome/browser/chromeos/gdata/drive_cache.cc index 3b34ff4..174cf30 100644 --- a/chrome/browser/chromeos/gdata/drive_cache.cc +++ b/chrome/browser/chromeos/gdata/drive_cache.cc @@ -14,6 +14,7 @@ #include "base/sys_info.h" #include "chrome/browser/chromeos/gdata/drive.pb.h" #include "chrome/browser/chromeos/gdata/drive_cache_metadata.h" +#include "chrome/browser/chromeos/gdata/drive_cache_observer.h" #include "chrome/browser/chromeos/gdata/drive_file_system_util.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_constants.h" @@ -373,12 +374,12 @@ bool DriveCache::IsUnderDriveCacheDirectory(const FilePath& path) const { return cache_root_path_ == path || cache_root_path_.IsParent(path); } -void DriveCache::AddObserver(Observer* observer) { +void DriveCache::AddObserver(DriveCacheObserver* observer) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); observers_.AddObserver(observer); } -void DriveCache::RemoveObserver(Observer* observer) { +void DriveCache::RemoveObserver(DriveCacheObserver* observer) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); observers_.RemoveObserver(observer); } @@ -1513,7 +1514,9 @@ void DriveCache::OnPinned(DriveFileError* error, callback.Run(*error, resource_id, md5); if (*error == DRIVE_FILE_OK) - FOR_EACH_OBSERVER(Observer, observers_, OnCachePinned(resource_id, md5)); + FOR_EACH_OBSERVER(DriveCacheObserver, + observers_, + OnCachePinned(resource_id, md5)); } void DriveCache::OnUnpinned(DriveFileError* error, @@ -1527,7 +1530,9 @@ void DriveCache::OnUnpinned(DriveFileError* error, callback.Run(*error, resource_id, md5); if (*error == DRIVE_FILE_OK) - FOR_EACH_OBSERVER(Observer, observers_, OnCacheUnpinned(resource_id, md5)); + FOR_EACH_OBSERVER(DriveCacheObserver, + observers_, + OnCacheUnpinned(resource_id, md5)); // Now the file is moved from "persistent" to "tmp" directory. // It's a chance to free up space if needed. @@ -1551,7 +1556,9 @@ void DriveCache::OnCommitDirty(DriveFileError* error, callback.Run(*error, resource_id, md5); if (*error == DRIVE_FILE_OK) - FOR_EACH_OBSERVER(Observer, observers_, OnCacheCommitted(resource_id)); + FOR_EACH_OBSERVER(DriveCacheObserver, + observers_, + OnCacheCommitted(resource_id)); } void DriveCache::GetCacheEntryHelper(const std::string& resource_id, diff --git a/chrome/browser/chromeos/gdata/drive_cache.h b/chrome/browser/chromeos/gdata/drive_cache.h index 19fd4cc..17bc6fc 100644 --- a/chrome/browser/chromeos/gdata/drive_cache.h +++ b/chrome/browser/chromeos/gdata/drive_cache.h @@ -27,6 +27,7 @@ namespace gdata { class DriveCacheEntry; class DriveCacheMetadata; +class DriveCacheObserver; // Callback for SetMountedStateOnUIThread and ClearAllOnUIThread. typedef base::Callback<void(DriveFileError error, @@ -109,24 +110,6 @@ class DriveCache { FILE_OPERATION_COPY, }; - // Used to notify events. All events are notified on UI thread. - class Observer { - public: - // Triggered when a file has been pinned successfully. - virtual void OnCachePinned(const std::string& resource_id, - const std::string& md5) {} - - // Triggered when a file has been unpinned successfully. - virtual void OnCacheUnpinned(const std::string& resource_id, - const std::string& md5) {} - - // Triggered when a dirty file has been committed (saved) successfully. - virtual void OnCacheCommitted(const std::string& resource_id) {} - - protected: - virtual ~Observer() {} - }; - // Returns the sub-directory under drive cache directory for the given sub // directory type. Example: <user_profile_dir>/GCache/v1/tmp // @@ -149,11 +132,11 @@ class DriveCache { // Adds observer. // Must be called on UI thread. - void AddObserver(Observer* observer); + void AddObserver(DriveCacheObserver* observer); // Removes observer. // Must be called on UI thread. - void RemoveObserver(Observer* observer); + void RemoveObserver(DriveCacheObserver* observer); // Gets the cache entry by the given resource ID and MD5. // See also GetCacheEntry(). @@ -452,7 +435,7 @@ class DriveCache { scoped_ptr<DriveCacheMetadata> metadata_; // List of observers, this member must be accessed on UI thread. - ObserverList<Observer> observers_; + ObserverList<DriveCacheObserver> observers_; // Note: This should remain the last member so it'll be destroyed and // invalidate its weak pointers before any other members are destroyed. diff --git a/chrome/browser/chromeos/gdata/drive_cache_observer.h b/chrome/browser/chromeos/gdata/drive_cache_observer.h new file mode 100644 index 0000000..ef95dec --- /dev/null +++ b/chrome/browser/chromeos/gdata/drive_cache_observer.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_DRIVE_CACHE_OBSERVER_H_ +#define CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_CACHE_OBSERVER_H_ + +#include <string> + +namespace gdata { + +// Interface for classes that need to observe events from DriveCache. +// All events are notified on UI thread. +class DriveCacheObserver { + public: + // Triggered when a file has been pinned successfully. + virtual void OnCachePinned(const std::string& resource_id, + const std::string& md5) {} + + // Triggered when a file has been unpinned successfully. + virtual void OnCacheUnpinned(const std::string& resource_id, + const std::string& md5) {} + + // Triggered when a dirty file has been committed (saved) successfully. + virtual void OnCacheCommitted(const std::string& resource_id) {} + + protected: + virtual ~DriveCacheObserver() {} +}; + +} // namespace gdata + +#endif // CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_CACHE_OBSERVER_H_ diff --git a/chrome/browser/chromeos/gdata/drive_file_system.cc b/chrome/browser/chromeos/gdata/drive_file_system.cc index db2ef6b..a4505d8 100644 --- a/chrome/browser/chromeos/gdata/drive_file_system.cc +++ b/chrome/browser/chromeos/gdata/drive_file_system.cc @@ -16,11 +16,13 @@ #include "chrome/browser/api/prefs/pref_change_registrar.h" #include "chrome/browser/chromeos/gdata/drive.pb.h" #include "chrome/browser/chromeos/gdata/drive_files.h" +#include "chrome/browser/chromeos/gdata/drive_file_system_observer.h" #include "chrome/browser/chromeos/gdata/drive_file_system_util.h" #include "chrome/browser/chromeos/gdata/drive_function_remove.h" #include "chrome/browser/chromeos/gdata/drive_scheduler.h" #include "chrome/browser/chromeos/gdata/drive_service_interface.h" #include "chrome/browser/chromeos/gdata/drive_uploader.h" +#include "chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.h" #include "chrome/browser/chromeos/gdata/gdata_wapi_feed_processor.h" #include "chrome/browser/google_apis/drive_api_parser.h" #include "chrome/browser/google_apis/gdata_util.h" @@ -101,7 +103,7 @@ void OnAddUploadFileCompleted( // The class to wait for the initial load of root feed and runs the callback // after the initialization. -class InitialLoadObserver : public DriveFileSystemInterface::Observer { +class InitialLoadObserver : public DriveFileSystemObserver { public: InitialLoadObserver(DriveFileSystemInterface* file_system, const FileOperationCallback& callback) @@ -515,14 +517,12 @@ DriveFileSystem::~DriveFileSystem() { drive_service_->CancelAll(); } -void DriveFileSystem::AddObserver( - DriveFileSystemInterface::Observer* observer) { +void DriveFileSystem::AddObserver(DriveFileSystemObserver* observer) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); observers_.AddObserver(observer); } -void DriveFileSystem::RemoveObserver( - DriveFileSystemInterface::Observer* observer) { +void DriveFileSystem::RemoveObserver(DriveFileSystemObserver* observer) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); observers_.RemoveObserver(observer); } @@ -2338,21 +2338,21 @@ void DriveFileSystem::SearchAsyncOnUIThread( void DriveFileSystem::OnDirectoryChanged(const FilePath& directory_path) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - FOR_EACH_OBSERVER(DriveFileSystemInterface::Observer, observers_, + FOR_EACH_OBSERVER(DriveFileSystemObserver, observers_, OnDirectoryChanged(directory_path)); } void DriveFileSystem::OnDocumentFeedFetched(int num_accumulated_entries) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - FOR_EACH_OBSERVER(DriveFileSystemInterface::Observer, observers_, + FOR_EACH_OBSERVER(DriveFileSystemObserver, observers_, OnDocumentFeedFetched(num_accumulated_entries)); } void DriveFileSystem::OnFeedFromServerLoaded() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - FOR_EACH_OBSERVER(DriveFileSystemInterface::Observer, observers_, + FOR_EACH_OBSERVER(DriveFileSystemObserver, observers_, OnFeedFromServerLoaded()); } @@ -2598,7 +2598,7 @@ void DriveFileSystem::NotifyFileSystemMounted() { DVLOG(1) << "File System is mounted"; // Notify the observers that the file system is mounted. - FOR_EACH_OBSERVER(DriveFileSystemInterface::Observer, observers_, + FOR_EACH_OBSERVER(DriveFileSystemObserver, observers_, OnFileSystemMounted()); } @@ -2607,7 +2607,7 @@ void DriveFileSystem::NotifyFileSystemToBeUnmounted() { DVLOG(1) << "File System is to be unmounted"; // Notify the observers that the file system is being unmounted. - FOR_EACH_OBSERVER(DriveFileSystemInterface::Observer, observers_, + FOR_EACH_OBSERVER(DriveFileSystemObserver, observers_, OnFileSystemBeingUnmounted()); } @@ -2621,7 +2621,8 @@ void DriveFileSystem::NotifyInitialLoadFinishedAndRun( resource_metadata_->set_origin(UNINITIALIZED); // Notify the observers that root directory has been initialized. - FOR_EACH_OBSERVER(DriveFileSystemInterface::Observer, observers_, + FOR_EACH_OBSERVER(DriveFileSystemObserver, + observers_, OnInitialLoadFinished(error)); callback.Run(error); @@ -2898,7 +2899,7 @@ void DriveFileSystem::SetHideHostedDocuments(bool hide) { const FilePath root_path = resource_metadata_->root()->GetFilePath(); // Kick off directory refresh when this setting changes. - FOR_EACH_OBSERVER(DriveFileSystemInterface::Observer, observers_, + FOR_EACH_OBSERVER(DriveFileSystemObserver, observers_, OnDirectoryChanged(root_path)); } diff --git a/chrome/browser/chromeos/gdata/drive_file_system.h b/chrome/browser/chromeos/gdata/drive_file_system.h index 5f83d23..8cb9f9c 100644 --- a/chrome/browser/chromeos/gdata/drive_file_system.h +++ b/chrome/browser/chromeos/gdata/drive_file_system.h @@ -14,7 +14,7 @@ #include "base/timer.h" #include "chrome/browser/chromeos/gdata/drive_cache.h" #include "chrome/browser/chromeos/gdata/drive_file_system_interface.h" -#include "chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.h" +#include "chrome/browser/chromeos/gdata/gdata_wapi_feed_loader_observer.h" #include "chrome/browser/google_apis/gdata_errorcode.h" #include "content/public/browser/notification_observer.h" @@ -27,16 +27,20 @@ class SequencedTaskRunner; namespace gdata { +class DocumentFeed; +class DriveFileSystemObserver; class DriveFunctionRemove; class DriveResourceMetadata; class DriveServiceInterface; +class DriveScheduler; class DriveUploaderInterface; class DriveWebAppsRegistryInterface; -class DriveScheduler; +class GDataWapiFeedLoader; +struct LoadFeedParams; // The production implementation of DriveFileSystemInterface. class DriveFileSystem : public DriveFileSystemInterface, - public GDataWapiFeedLoader::Observer, + public GDataWapiFeedLoaderObserver, public content::NotificationObserver { public: DriveFileSystem(Profile* profile, @@ -49,10 +53,8 @@ class DriveFileSystem : public DriveFileSystemInterface, // DriveFileSystem overrides. virtual void Initialize() OVERRIDE; - virtual void AddObserver( - DriveFileSystemInterface::Observer* observer) OVERRIDE; - virtual void RemoveObserver( - DriveFileSystemInterface::Observer* observer) OVERRIDE; + virtual void AddObserver(DriveFileSystemObserver* observer) OVERRIDE; + virtual void RemoveObserver(DriveFileSystemObserver* observer) OVERRIDE; virtual void StartInitialFeedFetch() OVERRIDE; virtual void StartUpdates() OVERRIDE; virtual void StopUpdates() OVERRIDE; @@ -922,7 +924,7 @@ class DriveFileSystem : public DriveFileSystemInterface, // The loader is used to load the feeds. scoped_ptr<GDataWapiFeedLoader> feed_loader_; - ObserverList<DriveFileSystemInterface::Observer> observers_; + ObserverList<DriveFileSystemObserver> observers_; scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; diff --git a/chrome/browser/chromeos/gdata/drive_file_system_interface.h b/chrome/browser/chromeos/gdata/drive_file_system_interface.h index d89a850..80e86c9 100644 --- a/chrome/browser/chromeos/gdata/drive_file_system_interface.h +++ b/chrome/browser/chromeos/gdata/drive_file_system_interface.h @@ -17,6 +17,7 @@ namespace gdata { class DocumentEntry; class DriveEntryProto; +class DriveFileSystemObserver; typedef std::vector<DriveEntryProto> DriveEntryProtoVector; @@ -72,41 +73,13 @@ class DriveFileSystemInterface { public: virtual ~DriveFileSystemInterface() {} - // Used to notify events on the file system. - // All events are notified on UI thread. - class Observer { - public: - // Triggered when a content of a directory has been changed. - // |directory_path| is a virtual directory path (/drive/...) representing - // changed directory. - virtual void OnDirectoryChanged(const FilePath& directory_path) {} - - // Triggered when the file system is initially loaded. - virtual void OnInitialLoadFinished(DriveFileError error) {} - - // Triggered when a document feed is fetched. |num_accumulated_entries| - // tells the number of entries fetched so far. - virtual void OnDocumentFeedFetched(int num_accumulated_entries) {} - - // Triggered when the feed from the server is loaded. - virtual void OnFeedFromServerLoaded() {} - - // Triggered when the file system is mounted. - virtual void OnFileSystemMounted() {} - // Triggered when the file system is being unmounted. - virtual void OnFileSystemBeingUnmounted() {} - - protected: - virtual ~Observer() {} - }; - // Initializes the object. This function should be called before any // other functions. virtual void Initialize() = 0; // Adds and removes the observer. - virtual void AddObserver(Observer* observer) = 0; - virtual void RemoveObserver(Observer* observer) = 0; + virtual void AddObserver(DriveFileSystemObserver* observer) = 0; + virtual void RemoveObserver(DriveFileSystemObserver* observer) = 0; // Starts initial feed fetch from the server. virtual void StartInitialFeedFetch() = 0; diff --git a/chrome/browser/chromeos/gdata/drive_file_system_observer.h b/chrome/browser/chromeos/gdata/drive_file_system_observer.h new file mode 100644 index 0000000..a2b116e --- /dev/null +++ b/chrome/browser/chromeos/gdata/drive_file_system_observer.h @@ -0,0 +1,52 @@ +// 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_DRIVE_FILE_SYSTEM_OBSERVER_H_ +#define CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_FILE_SYSTEM_OBSERVER_H_ + +#include "chrome/browser/google_apis/gdata_errorcode.h" + +class FilePath; + +namespace gdata { + +// Interface for classes that need to observe events from classes implementing +// DriveFileSystemInterface. +// All events are notified on UI thread. +class DriveFileSystemObserver { + public: + // Triggered when a content of a directory has been changed. + // |directory_path| is a virtual directory path (/drive/...) representing + // changed directory. + virtual void OnDirectoryChanged(const FilePath& directory_path) { + } + + // Triggered when the file system is initially loaded. + virtual void OnInitialLoadFinished(DriveFileError error) { + } + + // Triggered when a document feed is fetched. |num_accumulated_entries| + // tells the number of entries fetched so far. + virtual void OnDocumentFeedFetched(int num_accumulated_entries) { + } + + // Triggered when the feed from the server is loaded. + virtual void OnFeedFromServerLoaded() { + } + + // Triggered when the file system is mounted. + virtual void OnFileSystemMounted() { + } + + // Triggered when the file system is being unmounted. + virtual void OnFileSystemBeingUnmounted() { + } + + protected: + virtual ~DriveFileSystemObserver() {} +}; + +} // namespace gdata + +#endif // CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_FILE_SYSTEM_OBSERVER_H_ diff --git a/chrome/browser/chromeos/gdata/drive_sync_client.cc b/chrome/browser/chromeos/gdata/drive_sync_client.cc index fe8cb29..e7b3a86 100644 --- a/chrome/browser/chromeos/gdata/drive_sync_client.cc +++ b/chrome/browser/chromeos/gdata/drive_sync_client.cc @@ -11,6 +11,7 @@ #include "base/message_loop_proxy.h" #include "chrome/browser/api/prefs/pref_change_registrar.h" #include "chrome/browser/chromeos/gdata/drive.pb.h" +#include "chrome/browser/chromeos/gdata/drive_file_system_interface.h" #include "chrome/browser/chromeos/gdata/drive_file_system_util.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" diff --git a/chrome/browser/chromeos/gdata/drive_sync_client.h b/chrome/browser/chromeos/gdata/drive_sync_client.h index 4e8ebb5..5cdbf26 100644 --- a/chrome/browser/chromeos/gdata/drive_sync_client.h +++ b/chrome/browser/chromeos/gdata/drive_sync_client.h @@ -13,7 +13,9 @@ #include "base/memory/weak_ptr.h" #include "base/time.h" #include "chrome/browser/chromeos/gdata/drive_cache.h" -#include "chrome/browser/chromeos/gdata/drive_file_system_interface.h" +#include "chrome/browser/chromeos/gdata/drive_cache_observer.h" +#include "chrome/browser/chromeos/gdata/drive_file_system_observer.h" +#include "chrome/browser/chromeos/gdata/drive_resource_metadata.h" #include "content/public/browser/notification_observer.h" #include "net/base/network_change_notifier.h" @@ -22,6 +24,9 @@ class PrefChangeRegistrar; namespace gdata { +class DriveEntryProto; +class DriveFileSystemInterface; + // The DriveSyncClient is used to synchronize pinned files on Drive and the // cache on the local drive. The sync client works as follows. // @@ -40,8 +45,8 @@ namespace gdata { // edited) files to Drive. Will work on this once downloading is done. // crosbug.com/27836. class DriveSyncClient - : public DriveFileSystemInterface::Observer, - public DriveCache::Observer, + : public DriveFileSystemObserver, + public DriveCacheObserver, public content::NotificationObserver, public net::NetworkChangeNotifier::ConnectionTypeObserver{ public: diff --git a/chrome/browser/chromeos/gdata/drive_task_executor.cc b/chrome/browser/chromeos/gdata/drive_task_executor.cc index 67e54bb..7699dcf 100644 --- a/chrome/browser/chromeos/gdata/drive_task_executor.cc +++ b/chrome/browser/chromeos/gdata/drive_task_executor.cc @@ -11,6 +11,7 @@ #include "base/string_util.h" #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" #include "chrome/browser/chromeos/gdata/drive.pb.h" +#include "chrome/browser/chromeos/gdata/drive_file_system_interface.h" #include "chrome/browser/chromeos/gdata/drive_service_interface.h" #include "chrome/browser/chromeos/gdata/drive_system_service.h" #include "chrome/browser/profiles/profile.h" diff --git a/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc b/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc index ef6e935..6d64042 100644 --- a/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc +++ b/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc @@ -19,6 +19,7 @@ #include "chrome/browser/chromeos/gdata/drive_file_system_util.h" #include "chrome/browser/chromeos/gdata/drive_service_interface.h" #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" +#include "chrome/browser/chromeos/gdata/gdata_wapi_feed_loader_observer.h" #include "chrome/browser/chromeos/gdata/gdata_wapi_feed_processor.h" #include "chrome/browser/google_apis/drive_api_parser.h" #include "chrome/browser/google_apis/gdata_util.h" @@ -229,12 +230,13 @@ GDataWapiFeedLoader::GDataWapiFeedLoader( GDataWapiFeedLoader::~GDataWapiFeedLoader() { } -void GDataWapiFeedLoader::AddObserver(Observer* observer) { +void GDataWapiFeedLoader::AddObserver(GDataWapiFeedLoaderObserver* observer) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); observers_.AddObserver(observer); } -void GDataWapiFeedLoader::RemoveObserver(Observer* observer) { +void GDataWapiFeedLoader::RemoveObserver( + GDataWapiFeedLoaderObserver* observer) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); observers_.RemoveObserver(observer); } @@ -508,7 +510,9 @@ void GDataWapiFeedLoader::OnFeedFromServerLoaded( if (!params->load_finished_callback.is_null()) params->load_finished_callback.Run(DRIVE_FILE_OK); - FOR_EACH_OBSERVER(Observer, observers_, OnFeedFromServerLoaded()); + FOR_EACH_OBSERVER(GDataWapiFeedLoaderObserver, + observers_, + OnFeedFromServerLoaded()); } void GDataWapiFeedLoader::OnGetDocuments( @@ -611,7 +615,7 @@ void GDataWapiFeedLoader::OnParseFeed(scoped_ptr<LoadFeedParams> params, } // Notify the observers that all document feeds are fetched. - FOR_EACH_OBSERVER(Observer, observers_, + FOR_EACH_OBSERVER(GDataWapiFeedLoaderObserver, observers_, OnDocumentFeedFetched(num_accumulated_entries)); UMA_HISTOGRAM_TIMES("Drive.EntireFeedLoadTime", @@ -715,7 +719,7 @@ void GDataWapiFeedLoader::OnGetChangelist( } // Notify the observers that all document feeds are fetched. - FOR_EACH_OBSERVER(Observer, observers_, + FOR_EACH_OBSERVER(GDataWapiFeedLoaderObserver, observers_, OnDocumentFeedFetched(num_accumulated_entries)); UMA_HISTOGRAM_TIMES("Drive.EntireFeedLoadTime", @@ -741,7 +745,7 @@ void GDataWapiFeedLoader::OnNotifyDocumentFeedFetched( if (ui_state->num_showing_documents + kFetchUiUpdateStep <= ui_state->num_fetched_documents) { ui_state->num_showing_documents += kFetchUiUpdateStep; - FOR_EACH_OBSERVER(Observer, observers_, + FOR_EACH_OBSERVER(GDataWapiFeedLoaderObserver, observers_, OnDocumentFeedFetched(ui_state->num_showing_documents)); int num_remaining_ui_updates = @@ -902,7 +906,7 @@ DriveFileError GDataWapiFeedLoader::UpdateFromFeed( if (should_notify_directory_changed) { for (std::set<FilePath>::iterator dir_iter = changed_dirs.begin(); dir_iter != changed_dirs.end(); ++dir_iter) { - FOR_EACH_OBSERVER(Observer, observers_, + FOR_EACH_OBSERVER(GDataWapiFeedLoaderObserver, observers_, OnDirectoryChanged(*dir_iter)); } } diff --git a/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.h b/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.h index 2e6c22e..5a3a651 100644 --- a/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.h +++ b/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.h @@ -27,6 +27,7 @@ class DocumentFeed; class DriveCache; class DriveServiceInterface; class DriveWebAppsRegistryInterface; +class GDataWapiFeedLoaderObserver; struct GetDocumentsUiState; struct LoadFeedParams; @@ -91,26 +92,6 @@ struct LoadRootFeedParams { // Documents List API) and load the cached proto file. class GDataWapiFeedLoader { public: - // Used to notify events from the loader. - // All events are notified on UI thread. - class Observer { - public: - // Triggered when a content of a directory has been changed. - // |directory_path| is a virtual directory path representing the - // changed directory. - virtual void OnDirectoryChanged(const FilePath& directory_path) {} - - // Triggered when a document feed is fetched. |num_accumulated_entries| - // tells the number of entries fetched so far. - virtual void OnDocumentFeedFetched(int num_accumulated_entries) {} - - // Triggered when the feed from the server is loaded. - virtual void OnFeedFromServerLoaded() {} - - protected: - virtual ~Observer() {} - }; - GDataWapiFeedLoader( DriveResourceMetadata* resource_metadata, DriveServiceInterface* drive_service, @@ -120,8 +101,8 @@ class GDataWapiFeedLoader { ~GDataWapiFeedLoader(); // Adds and removes the observer. - void AddObserver(Observer* observer); - void RemoveObserver(Observer* observer); + void AddObserver(GDataWapiFeedLoaderObserver* observer); + void RemoveObserver(GDataWapiFeedLoaderObserver* observer); // Starts root feed load from the cache. If successful, runs |callback| to // tell the caller that the loading was successful. @@ -253,7 +234,7 @@ class GDataWapiFeedLoader { DriveWebAppsRegistryInterface* webapps_registry_; // Not owned. DriveCache* cache_; // Not owned. scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; - ObserverList<Observer> observers_; + ObserverList<GDataWapiFeedLoaderObserver> observers_; // Note: This should remain the last member so it'll be destroyed and // invalidate its weak pointers before any other members are destroyed. diff --git a/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader_observer.h b/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader_observer.h new file mode 100644 index 0000000..a242e81 --- /dev/null +++ b/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader_observer.h @@ -0,0 +1,39 @@ +// 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_GDATA_WAPI_FEED_LOADER_OBSERVER_H_ +#define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_WAPI_FEED_LOADER_OBSERVER_H_ + +#include <string> + +class FilePath; + +namespace gdata { + +// Interface for classes that need to observe events from GdataWapiFeedLoader. +// All events are notified on UI thread. +class GDataWapiFeedLoaderObserver { + public: + // Triggered when a content of a directory has been changed. + // |directory_path| is a virtual directory path representing the + // changed directory. + virtual void OnDirectoryChanged(const FilePath& directory_path) { + } + + // Triggered when a document feed is fetched. |num_accumulated_entries| + // tells the number of entries fetched so far. + virtual void OnDocumentFeedFetched(int num_accumulated_entries) { + } + + // Triggered when the feed from the server is loaded. + virtual void OnFeedFromServerLoaded() { + } + + protected: + virtual ~GDataWapiFeedLoaderObserver() {} +}; + +} // namespace gdata + +#endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_WAPI_FEED_LOADER_OBSERVER_H_ diff --git a/chrome/browser/chromeos/gdata/gdata_wapi_service.cc b/chrome/browser/chromeos/gdata/gdata_wapi_service.cc index 5d2165d..5b5eb9a 100644 --- a/chrome/browser/chromeos/gdata/gdata_wapi_service.cc +++ b/chrome/browser/chromeos/gdata/gdata_wapi_service.cc @@ -9,6 +9,7 @@ #include "base/bind.h" #include "base/message_loop_proxy.h" +#include "chrome/browser/google_apis/auth_service.h" #include "chrome/browser/google_apis/drive_api_operations.h" #include "chrome/browser/google_apis/gdata_operations.h" #include "chrome/browser/google_apis/gdata_util.h" diff --git a/chrome/browser/chromeos/gdata/gdata_wapi_service.h b/chrome/browser/chromeos/gdata/gdata_wapi_service.h index 53d7084..60d53b1 100644 --- a/chrome/browser/chromeos/gdata/gdata_wapi_service.h +++ b/chrome/browser/chromeos/gdata/gdata_wapi_service.h @@ -11,7 +11,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "chrome/browser/chromeos/gdata/drive_service_interface.h" -#include "chrome/browser/google_apis/auth_service.h" +#include "chrome/browser/google_apis/auth_service_observer.h" #include "chrome/browser/google_apis/gdata_operations.h" class FilePath; @@ -20,6 +20,7 @@ class Profile; namespace gdata { +class AuthService; class OperationRunner; // This class provides documents feed service calls for WAPI (codename for @@ -27,8 +28,8 @@ class OperationRunner; // Details of API call are abstracted in each operation class and this class // works as a thin wrapper for the API. class GDataWapiService : public DriveServiceInterface, - public AuthService::Observer, - public OperationRegistry::Observer { + public AuthServiceObserver, + public OperationRegistryObserver { public: // Instance is usually created by DriveSystemServiceFactory and owned by // DriveFileSystem. diff --git a/chrome/browser/chromeos/gdata/gdata_wapi_service_browsertest.cc b/chrome/browser/chromeos/gdata/gdata_wapi_service_browsertest.cc index 5aac75c..3b6b0d9 100644 --- a/chrome/browser/chromeos/gdata/gdata_wapi_service_browsertest.cc +++ b/chrome/browser/chromeos/gdata/gdata_wapi_service_browsertest.cc @@ -8,6 +8,7 @@ #include "base/file_util.h" #include "base/json/json_reader.h" #include "chrome/browser/chromeos/gdata/gdata_wapi_service.h" +#include "chrome/browser/google_apis/auth_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/test/base/in_process_browser_test.h" diff --git a/chrome/browser/chromeos/gdata/mock_directory_change_observer.h b/chrome/browser/chromeos/gdata/mock_directory_change_observer.h index 56dc1bf..b3a01e0 100644 --- a/chrome/browser/chromeos/gdata/mock_directory_change_observer.h +++ b/chrome/browser/chromeos/gdata/mock_directory_change_observer.h @@ -5,13 +5,14 @@ #ifndef CHROME_BROWSER_CHROMEOS_GDATA_MOCK_DIRECTORY_CHANGE_OBSERVER_H_ #define CHROME_BROWSER_CHROMEOS_GDATA_MOCK_DIRECTORY_CHANGE_OBSERVER_H_ -#include "chrome/browser/chromeos/gdata/drive_file_system_interface.h" +#include "base/file_path.h" +#include "chrome/browser/chromeos/gdata/drive_file_system_observer.h" #include "testing/gmock/include/gmock/gmock.h" namespace gdata { // Mock for DriveFileSystemInterface::Observer::OnDirectoryChanged(). -class MockDirectoryChangeObserver : public DriveFileSystemInterface::Observer { +class MockDirectoryChangeObserver : public DriveFileSystemObserver { public: MockDirectoryChangeObserver(); virtual ~MockDirectoryChangeObserver(); diff --git a/chrome/browser/chromeos/gdata/mock_drive_cache_observer.h b/chrome/browser/chromeos/gdata/mock_drive_cache_observer.h index c43758e..c02ea90 100644 --- a/chrome/browser/chromeos/gdata/mock_drive_cache_observer.h +++ b/chrome/browser/chromeos/gdata/mock_drive_cache_observer.h @@ -7,13 +7,13 @@ #include <string> -#include "chrome/browser/chromeos/gdata/drive_cache.h" +#include "chrome/browser/chromeos/gdata/drive_cache_observer.h" #include "testing/gmock/include/gmock/gmock.h" namespace gdata { // Mock for DriveCache::Observer. -class MockDriveCacheObserver : public DriveCache::Observer { +class MockDriveCacheObserver : public DriveCacheObserver { public: MockDriveCacheObserver(); virtual ~MockDriveCacheObserver(); diff --git a/chrome/browser/chromeos/gdata/mock_drive_file_system.h b/chrome/browser/chromeos/gdata/mock_drive_file_system.h index e545cfc..8a34c74 100644 --- a/chrome/browser/chromeos/gdata/mock_drive_file_system.h +++ b/chrome/browser/chromeos/gdata/mock_drive_file_system.h @@ -12,6 +12,8 @@ namespace gdata { +class DriveFileSystemObserver; + // Mock for DriveFileSystemInterface. class MockDriveFileSystem : public DriveFileSystemInterface { public: @@ -20,8 +22,9 @@ class MockDriveFileSystem : public DriveFileSystemInterface { // DriveFileSystemInterface overrides. MOCK_METHOD0(Initialize, void()); - MOCK_METHOD1(AddObserver, void(Observer* observer)); - MOCK_METHOD1(RemoveObserver, void(Observer* observer)); + MOCK_METHOD1(AddObserver, void(DriveFileSystemObserver* observer)); + MOCK_METHOD1(RemoveObserver, + void(DriveFileSystemObserver* observer)); MOCK_METHOD0(StartInitialFeedFetch, void()); MOCK_METHOD0(StartUpdates, void()); MOCK_METHOD0(StopUpdates, void()); diff --git a/chrome/browser/chromeos/gdata/stale_cache_files_remover.h b/chrome/browser/chromeos/gdata/stale_cache_files_remover.h index 8940384..23c69da 100644 --- a/chrome/browser/chromeos/gdata/stale_cache_files_remover.h +++ b/chrome/browser/chromeos/gdata/stale_cache_files_remover.h @@ -8,18 +8,22 @@ #include <string> #include <vector> -#include "base/basictypes.h" -#include "chrome/browser/chromeos/gdata/drive_file_system_interface.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "chrome/browser/chromeos/gdata/drive.pb.h" +#include "chrome/browser/chromeos/gdata/drive_file_system_observer.h" +#include "chrome/browser/google_apis/gdata_errorcode.h" namespace gdata{ class DriveCache; -class DriveFileSystem; +class DriveCacheEntry; +class DriveFileSystemInterface; // This class removes stale cache files, which are present locally, but no // longer present on the server. This can happen if files are removed from the // server from other devices, or from the web interface. -class StaleCacheFilesRemover : public DriveFileSystemInterface::Observer { +class StaleCacheFilesRemover : public DriveFileSystemObserver { public: StaleCacheFilesRemover(DriveFileSystemInterface* file_system, DriveCache* cache); diff --git a/chrome/browser/google_apis/auth_service.cc b/chrome/browser/google_apis/auth_service.cc index 04a0bfb..d0dce3d 100644 --- a/chrome/browser/google_apis/auth_service.cc +++ b/chrome/browser/google_apis/auth_service.cc @@ -9,6 +9,7 @@ #include "base/bind.h" #include "base/message_loop_proxy.h" +#include "chrome/browser/google_apis/auth_service_observer.h" #include "chrome/browser/google_apis/operations_base.h" #include "chrome/browser/google_apis/task_util.h" #include "chrome/browser/signin/token_service.h" @@ -37,7 +38,9 @@ void AuthService::Initialize(Profile* profile) { content::Source<TokenService>(service)); if (!refresh_token_.empty()) - FOR_EACH_OBSERVER(Observer, observers_, OnOAuth2RefreshTokenChanged()); + FOR_EACH_OBSERVER(AuthServiceObserver, + observers_, + OnOAuth2RefreshTokenChanged()); } AuthService::AuthService(const std::vector<std::string>& scopes) @@ -96,11 +99,11 @@ void AuthService::OnAuthCompleted(const AuthStatusCallback& callback, callback.Run(error, access_token); } -void AuthService::AddObserver(Observer* observer) { +void AuthService::AddObserver(AuthServiceObserver* observer) { observers_.AddObserver(observer); } -void AuthService::RemoveObserver(Observer* observer) { +void AuthService::RemoveObserver(AuthServiceObserver* observer) { observers_.RemoveObserver(observer); } @@ -122,7 +125,9 @@ void AuthService::Observe(int type, } else { refresh_token_.clear(); } - FOR_EACH_OBSERVER(Observer, observers_, OnOAuth2RefreshTokenChanged()); + FOR_EACH_OBSERVER(AuthServiceObserver, + observers_, + OnOAuth2RefreshTokenChanged()); } } // namespace gdata diff --git a/chrome/browser/google_apis/auth_service.h b/chrome/browser/google_apis/auth_service.h index 5923a09..96a2220 100644 --- a/chrome/browser/google_apis/auth_service.h +++ b/chrome/browser/google_apis/auth_service.h @@ -20,6 +20,7 @@ class Profile; namespace gdata { class OperationRegistry; +class AuthServiceObserver; // This class provides authentication for Google services. // It integrates specific service integration with OAuth2 stack @@ -27,22 +28,13 @@ class OperationRegistry; // All public functions must be called on UI thread. class AuthService : public content::NotificationObserver { public: - class Observer { - public: - // Triggered when a new OAuth2 refresh token is received from TokenService. - virtual void OnOAuth2RefreshTokenChanged() = 0; - - protected: - virtual ~Observer() {} - }; - explicit AuthService(const std::vector<std::string>& scopes); virtual ~AuthService(); // Adds and removes the observer. AddObserver() should be called before // Initialize() as it can change the refresh token. - void AddObserver(Observer* observer); - void RemoveObserver(Observer* observer); + void AddObserver(AuthServiceObserver* observer); + void RemoveObserver(AuthServiceObserver* observer); // Initializes the auth service. Starts TokenService to retrieve the // refresh token. @@ -91,7 +83,7 @@ class AuthService : public content::NotificationObserver { std::string refresh_token_; std::string access_token_; std::vector<std::string> scopes_; - ObserverList<Observer> observers_; + ObserverList<AuthServiceObserver> observers_; content::NotificationRegistrar registrar_; diff --git a/chrome/browser/google_apis/auth_service_observer.h b/chrome/browser/google_apis/auth_service_observer.h new file mode 100644 index 0000000..4a0d0ec --- /dev/null +++ b/chrome/browser/google_apis/auth_service_observer.h @@ -0,0 +1,23 @@ +// 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_GOOGLE_APIS_AUTH_SERVICE_OBSERVER_H_ +#define CHROME_BROWSER_GOOGLE_APIS_AUTH_SERVICE_OBSERVER_H_ + +namespace gdata { + +// Interface for classes that need to observe events from AuthService. +// All events are notified on UI thread. +class AuthServiceObserver { + public: + // Triggered when a new OAuth2 refresh token is received from TokenService. + virtual void OnOAuth2RefreshTokenChanged() = 0; + + protected: + virtual ~AuthServiceObserver() {} +}; + +} // namespace gdata + +#endif // CHROME_BROWSER_GOOGLE_APIS_AUTH_SERVICE_OBSERVER_H_ diff --git a/chrome/browser/google_apis/operation_registry.cc b/chrome/browser/google_apis/operation_registry.cc index b3a7a2a..6b11b52 100644 --- a/chrome/browser/google_apis/operation_registry.cc +++ b/chrome/browser/google_apis/operation_registry.cc @@ -149,11 +149,11 @@ OperationRegistry::~OperationRegistry() { DCHECK(in_flight_operations_.IsEmpty()); } -void OperationRegistry::AddObserver(Observer* observer) { +void OperationRegistry::AddObserver(OperationRegistryObserver* observer) { observer_list_.AddObserver(observer); } -void OperationRegistry::RemoveObserver(Observer* observer) { +void OperationRegistry::RemoveObserver(OperationRegistryObserver* observer) { observer_list_.RemoveObserver(observer); } @@ -278,7 +278,9 @@ void OperationRegistry::OnOperationAuthFailed() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DVLOG(1) << "GDataOperation authentication failed."; - FOR_EACH_OBSERVER(Observer, observer_list_, OnAuthenticationFailed()); + FOR_EACH_OBSERVER(OperationRegistryObserver, + observer_list_, + OnAuthenticationFailed()); } bool OperationRegistry::IsFileTransferOperation( @@ -339,7 +341,9 @@ bool OperationRegistry::ShouldNotifyStatusNow( void OperationRegistry::NotifyStatusToObservers() { OperationProgressStatusList list(GetProgressStatusList()); if (ShouldNotifyStatusNow(list)) - FOR_EACH_OBSERVER(Observer, observer_list_, OnProgressUpdate(list)); + FOR_EACH_OBSERVER(OperationRegistryObserver, + observer_list_, + OnProgressUpdate(list)); } } // namespace gdata diff --git a/chrome/browser/google_apis/operation_registry.h b/chrome/browser/google_apis/operation_registry.h index 9dc1c2e..c9e7026 100644 --- a/chrome/browser/google_apis/operation_registry.h +++ b/chrome/browser/google_apis/operation_registry.h @@ -16,6 +16,8 @@ namespace gdata { +class OperationRegistryObserver; + // Unique ID to identify each operation. typedef int32 OperationID; @@ -66,7 +68,6 @@ struct OperationProgressStatus { }; typedef std::vector<OperationProgressStatus> OperationProgressStatusList; - // This class tracks all the in-flight GData operation objects and manage their // lifetime. class OperationRegistry { @@ -74,17 +75,6 @@ class OperationRegistry { OperationRegistry(); ~OperationRegistry(); - // Observer interface for listening changes in the active set of operations. - class Observer { - public: - // Called when a GData operation started, made some progress, or finished. - virtual void OnProgressUpdate(const OperationProgressStatusList& list) = 0; - // Called when GData authentication failed. - virtual void OnAuthenticationFailed() {} - protected: - virtual ~Observer() {} - }; - // Base class for operations that this registry class can maintain. // NotifyStart() passes the ownership of the Operation object to the registry. // In particular, calling NotifyFinish() causes the registry to delete the @@ -143,8 +133,8 @@ class OperationRegistry { // Sets an observer. The registry do NOT own observers; before destruction // they need to be removed from the registry. - void AddObserver(Observer* observer); - void RemoveObserver(Observer* observer); + void AddObserver(OperationRegistryObserver* observer); + void RemoveObserver(OperationRegistryObserver* observer); // Disables the notification suppression for testing purpose. void DisableNotificationFrequencyControlForTest(); @@ -173,13 +163,28 @@ class OperationRegistry { typedef IDMap<Operation, IDMapOwnPointer> OperationIDMap; OperationIDMap in_flight_operations_; - ObserverList<Observer> observer_list_; + ObserverList<OperationRegistryObserver> observer_list_; base::Time last_notification_; bool do_notification_frequency_control_; DISALLOW_COPY_AND_ASSIGN(OperationRegistry); }; +// Observer interface for listening changes in the active set of operations. +class OperationRegistryObserver { + public: + // Called when a GData operation started, made some progress, or finished. + virtual void OnProgressUpdate(const OperationProgressStatusList& list) { + } + + // Called when GData authentication failed. + virtual void OnAuthenticationFailed() { + } + + protected: + virtual ~OperationRegistryObserver() {} +}; + } // namespace gdata #endif // CHROME_BROWSER_GOOGLE_APIS_OPERATION_REGISTRY_H_ diff --git a/chrome/browser/google_apis/operation_registry_unittest.cc b/chrome/browser/google_apis/operation_registry_unittest.cc index 56be5a8..3bb4c6b 100644 --- a/chrome/browser/google_apis/operation_registry_unittest.cc +++ b/chrome/browser/google_apis/operation_registry_unittest.cc @@ -7,6 +7,7 @@ #include "base/compiler_specific.h" #include "base/memory/weak_ptr.h" #include "base/message_loop.h" +#include "chrome/browser/google_apis/operation_registry.h" #include "content/public/test/test_browser_thread.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -57,7 +58,7 @@ class MockOtherOperation : public MockOperation { FilePath(FILE_PATH_LITERAL("/dummy/other"))) {} }; -class TestObserver : public OperationRegistry::Observer { +class TestObserver : public OperationRegistryObserver { public: virtual void OnProgressUpdate( const OperationProgressStatusList& list) OVERRIDE { |