Commit 0407ff6a authored by iseki's avatar iseki Committed by Commit bot

Add notification and observer to copy the file between other users.

* NotificationRegister and NotificationObserver is need to collect
  file information.

* This CL is related to https://codereview.chromium.org/530553006

BUG=412691

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

Cr-Commit-Position: refs/heads/master@{#294346}
parent 07e7a118
......@@ -269,6 +269,22 @@ std::string FileErrorToErrorName(base::File::Error error_code) {
}
}
void GrantAccessForAddedProfileToRunningInstance(Profile* added_profile,
Profile* running_profile) {
extensions::ProcessManager* const process_manager =
extensions::ExtensionSystem::Get(running_profile)->process_manager();
if (!process_manager)
return;
extensions::ExtensionHost* const extension_host =
process_manager->GetBackgroundHostForExtension(kFileManagerAppId);
if (!extension_host || !extension_host->render_process_host())
return;
const int id = extension_host->render_process_host()->GetID();
file_manager::util::SetupProfileFileAccessPermissions(id, added_profile);
}
// Checks if we should send a progress event or not according to the
// |last_time| of sending an event. If |always| is true, the function always
// returns true. If the function returns true, the function also updates
......@@ -464,6 +480,10 @@ void EventRouter::ObserveEvents() {
pref_change_registrar_->Add(prefs::kDisableDriveHostedFiles, callback);
pref_change_registrar_->Add(prefs::kDisableDrive, callback);
pref_change_registrar_->Add(prefs::kUse24HourClock, callback);
notification_registrar_.Add(this,
chrome::NOTIFICATION_PROFILE_ADDED,
content::NotificationService::AllSources());
}
// File watch setup routines.
......@@ -936,4 +956,14 @@ void EventRouter::OnFormatCompleted(const std::string& device_path,
// Do nothing.
}
void EventRouter::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
if (type == chrome::NOTIFICATION_PROFILE_ADDED) {
Profile* const added_profile = content::Source<Profile>(source).ptr();
if (!added_profile->IsOffTheRecord())
GrantAccessForAddedProfileToRunningInstance(added_profile, profile_);
}
}
} // namespace file_manager
......@@ -52,7 +52,8 @@ class EventRouter : public chromeos::NetworkStateHandlerObserver,
public drive::FileSystemObserver,
public drive::JobListObserver,
public drive::DriveServiceObserver,
public VolumeManagerObserver {
public VolumeManagerObserver,
public content::NotificationObserver {
public:
explicit EventRouter(Profile* profile);
virtual ~EventRouter();
......@@ -126,6 +127,11 @@ class EventRouter : public chromeos::NetworkStateHandlerObserver,
virtual void OnFormatCompleted(
const std::string& device_path, bool success) OVERRIDE;
// content::NotificationObserver overrides.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
private:
typedef std::map<base::FilePath, FileWatcher*> WatcherMap;
......@@ -197,6 +203,8 @@ class EventRouter : public chromeos::NetworkStateHandlerObserver,
scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
Profile* profile_;
content::NotificationRegistrar notification_registrar_;
scoped_ptr<DeviceEventRouter> device_event_router_;
// Note: This should remain the last member so it'll be destroyed and
......
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