Commit cc163833 authored by satorux's avatar satorux Committed by Commit bot

Get rid of FileManagerPrivateAPI class

The whole purpose of FileManagerPrivateAPI class was to hold an
EventRouter instance. It's simpler to just make EventRouter a
KeyedService and get rid of FileManagerPrivateAPI.

Note that BrowserContextKeyedAPI could not be used for EventRouter as
EventRouter needs a Profile rather than a BrowserContext.

In the next patch, EventRouter will be renamed to something like
FileManagerService.

BUG=412643
TEST=Files.app works as before

Review URL: https://codereview.chromium.org/553393002

Cr-Commit-Position: refs/heads/master@{#294351}
parent eacfb1e9
...@@ -388,6 +388,7 @@ EventRouter::EventRouter(Profile* profile) ...@@ -388,6 +388,7 @@ EventRouter::EventRouter(Profile* profile)
device_event_router_(new DeviceEventRouterImpl(profile)), device_event_router_(new DeviceEventRouterImpl(profile)),
weak_factory_(this) { weak_factory_(this) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
ObserveEvents();
} }
EventRouter::~EventRouter() { EventRouter::~EventRouter() {
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "chrome/common/extensions/api/file_manager_private.h" #include "chrome/common/extensions/api/file_manager_private.h"
#include "chromeos/disks/disk_mount_manager.h" #include "chromeos/disks/disk_mount_manager.h"
#include "chromeos/network/network_state_handler_observer.h" #include "chromeos/network/network_state_handler_observer.h"
#include "components/keyed_service/core/keyed_service.h"
#include "storage/browser/fileapi/file_system_operation.h" #include "storage/browser/fileapi/file_system_operation.h"
class PrefChangeRegistrar; class PrefChangeRegistrar;
...@@ -48,7 +49,8 @@ class DeviceEventRouter; ...@@ -48,7 +49,8 @@ class DeviceEventRouter;
// Monitors changes in disk mounts, network connection state and preferences // Monitors changes in disk mounts, network connection state and preferences
// affecting File Manager. Dispatches appropriate File Browser events. // affecting File Manager. Dispatches appropriate File Browser events.
class EventRouter : public chromeos::NetworkStateHandlerObserver, class EventRouter : public KeyedService,
public chromeos::NetworkStateHandlerObserver,
public drive::FileSystemObserver, public drive::FileSystemObserver,
public drive::JobListObserver, public drive::JobListObserver,
public drive::DriveServiceObserver, public drive::DriveServiceObserver,
...@@ -58,10 +60,8 @@ class EventRouter : public chromeos::NetworkStateHandlerObserver, ...@@ -58,10 +60,8 @@ class EventRouter : public chromeos::NetworkStateHandlerObserver,
explicit EventRouter(Profile* profile); explicit EventRouter(Profile* profile);
virtual ~EventRouter(); virtual ~EventRouter();
void Shutdown(); // KeyedService overrides.
virtual void Shutdown() OVERRIDE;
// Starts observing file system change events.
void ObserveEvents();
typedef base::Callback<void(bool success)> BoolCallback; typedef base::Callback<void(bool success)> BoolCallback;
...@@ -135,6 +135,9 @@ class EventRouter : public chromeos::NetworkStateHandlerObserver, ...@@ -135,6 +135,9 @@ class EventRouter : public chromeos::NetworkStateHandlerObserver,
private: private:
typedef std::map<base::FilePath, FileWatcher*> WatcherMap; typedef std::map<base::FilePath, FileWatcher*> WatcherMap;
// Starts observing file system change events.
void ObserveEvents();
// Called when prefs related to file manager change. // Called when prefs related to file manager change.
void OnFileManagerPrefsChanged(); void OnFileManagerPrefsChanged();
......
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/chromeos/extensions/file_manager/file_manager_private_api_factory.h" #include "chrome/browser/chromeos/extensions/file_manager/event_router_factory.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h" #include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/chromeos/extensions/file_manager/file_manager_private_api.h" #include "chrome/browser/chromeos/extensions/file_manager/event_router.h"
#include "chrome/browser/chromeos/file_manager/volume_manager_factory.h" #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h"
#include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -16,21 +16,19 @@ ...@@ -16,21 +16,19 @@
namespace file_manager { namespace file_manager {
// static // static
FileManagerPrivateAPI* EventRouter* EventRouterFactory::GetForProfile(Profile* profile) {
FileManagerPrivateAPIFactory::GetForProfile(Profile* profile) { return static_cast<EventRouter*>(
return static_cast<FileManagerPrivateAPI*>(
GetInstance()->GetServiceForBrowserContext(profile, true)); GetInstance()->GetServiceForBrowserContext(profile, true));
} }
// static // static
FileManagerPrivateAPIFactory* EventRouterFactory* EventRouterFactory::GetInstance() {
FileManagerPrivateAPIFactory::GetInstance() { return Singleton<EventRouterFactory>::get();
return Singleton<FileManagerPrivateAPIFactory>::get();
} }
FileManagerPrivateAPIFactory::FileManagerPrivateAPIFactory() EventRouterFactory::EventRouterFactory()
: BrowserContextKeyedServiceFactory( : BrowserContextKeyedServiceFactory(
"FileManagerPrivateAPI", "EventRouter",
BrowserContextDependencyManager::GetInstance()) { BrowserContextDependencyManager::GetInstance()) {
DependsOn(drive::DriveIntegrationServiceFactory::GetInstance()); DependsOn(drive::DriveIntegrationServiceFactory::GetInstance());
DependsOn( DependsOn(
...@@ -38,25 +36,25 @@ FileManagerPrivateAPIFactory::FileManagerPrivateAPIFactory() ...@@ -38,25 +36,25 @@ FileManagerPrivateAPIFactory::FileManagerPrivateAPIFactory()
DependsOn(VolumeManagerFactory::GetInstance()); DependsOn(VolumeManagerFactory::GetInstance());
} }
FileManagerPrivateAPIFactory::~FileManagerPrivateAPIFactory() { EventRouterFactory::~EventRouterFactory() {
} }
KeyedService* FileManagerPrivateAPIFactory::BuildServiceInstanceFor( KeyedService* EventRouterFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const { content::BrowserContext* context) const {
return new FileManagerPrivateAPI(Profile::FromBrowserContext(context)); return new EventRouter(Profile::FromBrowserContext(context));
} }
content::BrowserContext* FileManagerPrivateAPIFactory::GetBrowserContextToUse( content::BrowserContext* EventRouterFactory::GetBrowserContextToUse(
content::BrowserContext* context) const { content::BrowserContext* context) const {
// Explicitly and always allow this router in guest login mode. // Explicitly and always allow this router in guest login mode.
return chrome::GetBrowserContextOwnInstanceInIncognito(context); return chrome::GetBrowserContextOwnInstanceInIncognito(context);
} }
bool FileManagerPrivateAPIFactory::ServiceIsCreatedWithBrowserContext() const { bool EventRouterFactory::ServiceIsCreatedWithBrowserContext() const {
return true; return true;
} }
bool FileManagerPrivateAPIFactory::ServiceIsNULLWhileTesting() const { bool EventRouterFactory::ServiceIsNULLWhileTesting() const {
return true; return true;
} }
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_MANAGER_PRIVATE_API_FACTORY_H_ #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_EVENT_ROUTER_FACTORY_H_
#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_MANAGER_PRIVATE_API_FACTORY_H_ #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_EVENT_ROUTER_FACTORY_H_
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h" #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
...@@ -12,16 +12,16 @@ class Profile; ...@@ -12,16 +12,16 @@ class Profile;
namespace file_manager { namespace file_manager {
class FileManagerPrivateAPI; class EventRouter;
class FileManagerPrivateAPIFactory : public BrowserContextKeyedServiceFactory { class EventRouterFactory : public BrowserContextKeyedServiceFactory {
public: public:
// Returns the FileManagerPrivateAPI for |profile|, creating it if // Returns the EventRouter for |profile|, creating it if
// it is not yet created. // it is not yet created.
static FileManagerPrivateAPI* GetForProfile(Profile* profile); static EventRouter* GetForProfile(Profile* profile);
// Returns the FileManagerPrivateAPIFactory instance. // Returns the EventRouterFactory instance.
static FileManagerPrivateAPIFactory* GetInstance(); static EventRouterFactory* GetInstance();
protected: protected:
// BrowserContextKeyedBaseFactory overrides: // BrowserContextKeyedBaseFactory overrides:
...@@ -31,10 +31,10 @@ class FileManagerPrivateAPIFactory : public BrowserContextKeyedServiceFactory { ...@@ -31,10 +31,10 @@ class FileManagerPrivateAPIFactory : public BrowserContextKeyedServiceFactory {
virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; virtual bool ServiceIsNULLWhileTesting() const OVERRIDE;
private: private:
friend struct DefaultSingletonTraits<FileManagerPrivateAPIFactory>; friend struct DefaultSingletonTraits<EventRouterFactory>;
FileManagerPrivateAPIFactory(); EventRouterFactory();
virtual ~FileManagerPrivateAPIFactory(); virtual ~EventRouterFactory();
// BrowserContextKeyedServiceFactory: // BrowserContextKeyedServiceFactory:
virtual KeyedService* BuildServiceInstanceFor( virtual KeyedService* BuildServiceInstanceFor(
...@@ -43,4 +43,4 @@ class FileManagerPrivateAPIFactory : public BrowserContextKeyedServiceFactory { ...@@ -43,4 +43,4 @@ class FileManagerPrivateAPIFactory : public BrowserContextKeyedServiceFactory {
} // namespace file_manager } // namespace file_manager
#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_MANAGER_PRIVATE_API_FACTORY_H_ #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_EVENT_ROUTER_FACTORY_H_
// 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/extensions/file_manager/file_manager_private_api.h"
#include "chrome/browser/chromeos/extensions/file_manager/event_router.h"
#include "chrome/browser/chromeos/extensions/file_manager/file_manager_private_api_factory.h"
namespace file_manager {
FileManagerPrivateAPI::FileManagerPrivateAPI(Profile* profile)
: event_router_(new EventRouter(profile)) {
event_router_->ObserveEvents();
}
FileManagerPrivateAPI::~FileManagerPrivateAPI() {
}
void FileManagerPrivateAPI::Shutdown() {
event_router_->Shutdown();
}
// static
FileManagerPrivateAPI* FileManagerPrivateAPI::Get(Profile* profile) {
return FileManagerPrivateAPIFactory::GetForProfile(profile);
}
} // namespace file_manager
// 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_EXTENSIONS_FILE_MANAGER_FILE_MANAGER_PRIVATE_API_H_
#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_MANAGER_PRIVATE_API_H_
#include "base/memory/scoped_ptr.h"
#include "components/keyed_service/core/keyed_service.h"
class Profile;
namespace file_manager {
class EventRouter;
// Manages and registers the fileManagerPrivate API with the extension system.
class FileManagerPrivateAPI : public KeyedService {
public:
explicit FileManagerPrivateAPI(Profile* profile);
virtual ~FileManagerPrivateAPI();
// KeyedService overrides.
virtual void Shutdown() OVERRIDE;
// Convenience function to return the FileManagerPrivateAPI for a Profile.
static FileManagerPrivateAPI* Get(Profile* profile);
EventRouter* event_router() { return event_router_.get(); }
private:
scoped_ptr<EventRouter> event_router_;
};
} // namespace file_manager
#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_MANAGER_PRIVATE_API_H_
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "chrome/browser/chromeos/drive/file_system_interface.h" #include "chrome/browser/chromeos/drive/file_system_interface.h"
#include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/extensions/file_manager/event_router.h" #include "chrome/browser/chromeos/extensions/file_manager/event_router.h"
#include "chrome/browser/chromeos/extensions/file_manager/file_manager_private_api.h" #include "chrome/browser/chromeos/extensions/file_manager/event_router_factory.h"
#include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h"
#include "chrome/browser/chromeos/file_manager/fileapi_util.h" #include "chrome/browser/chromeos/file_manager/fileapi_util.h"
#include "chrome/browser/chromeos/file_manager/volume_manager.h" #include "chrome/browser/chromeos/file_manager/volume_manager.h"
...@@ -83,7 +83,7 @@ file_manager::EventRouter* GetEventRouterByProfileId(void* profile_id) { ...@@ -83,7 +83,7 @@ file_manager::EventRouter* GetEventRouterByProfileId(void* profile_id) {
if (!g_browser_process->profile_manager()->IsValidProfile(profile)) if (!g_browser_process->profile_manager()->IsValidProfile(profile))
return NULL; return NULL;
return file_manager::FileManagerPrivateAPI::Get(profile)->event_router(); return file_manager::EventRouterFactory::GetForProfile(profile);
} }
// Notifies the copy progress to extensions via event router. // Notifies the copy progress to extensions via event router.
...@@ -381,7 +381,7 @@ void FileManagerPrivateAddFileWatchFunction::PerformFileWatchOperation( ...@@ -381,7 +381,7 @@ void FileManagerPrivateAddFileWatchFunction::PerformFileWatchOperation(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
file_manager::EventRouter* event_router = file_manager::EventRouter* event_router =
file_manager::FileManagerPrivateAPI::Get(GetProfile())->event_router(); file_manager::EventRouterFactory::GetForProfile(GetProfile());
event_router->AddFileWatch( event_router->AddFileWatch(
local_path, local_path,
virtual_path, virtual_path,
...@@ -396,7 +396,7 @@ void FileManagerPrivateRemoveFileWatchFunction::PerformFileWatchOperation( ...@@ -396,7 +396,7 @@ void FileManagerPrivateRemoveFileWatchFunction::PerformFileWatchOperation(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
file_manager::EventRouter* event_router = file_manager::EventRouter* event_router =
file_manager::FileManagerPrivateAPI::Get(GetProfile())->event_router(); file_manager::EventRouterFactory::GetForProfile(GetProfile());
event_router->RemoveFileWatch(local_path, extension_id); event_router->RemoveFileWatch(local_path, extension_id);
Respond(true); Respond(true);
} }
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/extensions/file_manager/file_manager_private_api.h"
#include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h"
#include "chrome/browser/chromeos/file_manager/app_installer.h" #include "chrome/browser/chromeos/file_manager/app_installer.h"
#include "chrome/browser/chromeos/file_manager/zip_file_creator.h" #include "chrome/browser/chromeos/file_manager/zip_file_creator.h"
......
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
#include "extensions/browser/api/usb/usb_device_resource.h" #include "extensions/browser/api/usb/usb_device_resource.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/extensions/file_manager/file_manager_private_api_factory.h" #include "chrome/browser/chromeos/extensions/file_manager/event_router_factory.h"
#include "chrome/browser/chromeos/extensions/input_method_api.h" #include "chrome/browser/chromeos/extensions/input_method_api.h"
#include "chrome/browser/chromeos/extensions/media_player_api.h" #include "chrome/browser/chromeos/extensions/media_player_api.h"
#include "chrome/browser/extensions/api/input_ime/input_ime_api.h" #include "chrome/browser/extensions/api/input_ime/input_ime_api.h"
...@@ -157,7 +157,7 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() { ...@@ -157,7 +157,7 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
extensions::WebrtcAudioPrivateEventService::GetFactoryInstance(); extensions::WebrtcAudioPrivateEventService::GetFactoryInstance();
extensions::WebstoreAPI::GetFactoryInstance(); extensions::WebstoreAPI::GetFactoryInstance();
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
file_manager::FileManagerPrivateAPIFactory::GetInstance(); file_manager::EventRouterFactory::GetInstance();
#endif #endif
TokenCacheServiceFactory::GetInstance(); TokenCacheServiceFactory::GetInstance();
extensions::ExtensionGCMAppHandler::GetFactoryInstance(); extensions::ExtensionGCMAppHandler::GetFactoryInstance();
......
...@@ -1048,12 +1048,10 @@ ...@@ -1048,12 +1048,10 @@
'browser/chromeos/extensions/file_manager/device_event_router.h', 'browser/chromeos/extensions/file_manager/device_event_router.h',
'browser/chromeos/extensions/file_manager/event_router.cc', 'browser/chromeos/extensions/file_manager/event_router.cc',
'browser/chromeos/extensions/file_manager/event_router.h', 'browser/chromeos/extensions/file_manager/event_router.h',
'browser/chromeos/extensions/file_manager/event_router_factory.cc',
'browser/chromeos/extensions/file_manager/event_router_factory.h',
'browser/chromeos/extensions/file_manager/file_browser_handler_api.cc', 'browser/chromeos/extensions/file_manager/file_browser_handler_api.cc',
'browser/chromeos/extensions/file_manager/file_browser_handler_api.h', 'browser/chromeos/extensions/file_manager/file_browser_handler_api.h',
'browser/chromeos/extensions/file_manager/file_manager_private_api.cc',
'browser/chromeos/extensions/file_manager/file_manager_private_api.h',
'browser/chromeos/extensions/file_manager/file_manager_private_api_factory.cc',
'browser/chromeos/extensions/file_manager/file_manager_private_api_factory.h',
'browser/chromeos/extensions/file_manager/file_manager_private_api_functions.h', 'browser/chromeos/extensions/file_manager/file_manager_private_api_functions.h',
'browser/chromeos/extensions/file_manager/private_api_base.cc', 'browser/chromeos/extensions/file_manager/private_api_base.cc',
'browser/chromeos/extensions/file_manager/private_api_base.h', 'browser/chromeos/extensions/file_manager/private_api_base.h',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment