#include "chrome/browser/chromeos/login/screen_locker.h"
#include "chrome/browser/drive/drive_service_interface.h"
#include "chrome/browser/extensions/event_names.h"
+#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/pref_names.h"
#include "chromeos/network/network_state_handler.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_source.h"
+#include "content/public/browser/render_process_host.h"
#include "extensions/browser/event_router.h"
+#include "extensions/browser/extension_prefs.h"
+#include "extensions/browser/extension_system.h"
#include "webkit/common/fileapi/file_system_types.h"
#include "webkit/common/fileapi/file_system_util.h"
// Converts the job info to a IDL generated type.
void JobInfoToTransferStatus(
+ Profile* profile,
const std::string& extension_id,
const std::string& job_status,
const drive::JobInfo& job_info,
DCHECK(IsActiveFileTransferJobInfo(job_info));
scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue);
- GURL url = util::ConvertRelativeFilePathToFileSystemUrl(
- job_info.file_path, extension_id);
+ GURL url = util::ConvertDrivePathToFileSystemUrl(
+ profile, job_info.file_path, extension_id);
status->file_url = url.spec();
status->transfer_state = file_browser_private::ParseTransferState(job_status);
status->transfer_type =
}
// Checks for availability of the Google+ Photos app.
+// TODO(mtomasz): Replace with crbug.com/341902 solution.
bool IsGooglePhotosInstalled(Profile *profile) {
ExtensionService* service =
extensions::ExtensionSystem::Get(profile)->extension_service();
// Google+ Photos uses several ids for different channels. Therefore, all of
// them should be checked.
const std::string kGooglePlusPhotosIds[] = {
- "ebpbnabdhheoknfklmpddcdijjkmklkp", // G+ Photos staging
- "efjnaogkjbogokcnohkmnjdojkikgobo", // G+ Photos prod
- "ejegoaikibpmikoejfephaneibodccma" // G+ Photos dev
+ "ebpbnabdhheoknfklmpddcdijjkmklkp", // G+ Photos staging
+ "efjnaogkjbogokcnohkmnjdojkikgobo", // G+ Photos prod
+ "ejegoaikibpmikoejfephaneibodccma" // G+ Photos dev
};
for (size_t i = 0; i < arraysize(kGooglePlusPhotosIds); ++i) {
return false;
}
+// Checks if the Recovery Tool is running. This is a temporary solution.
+// TODO(mtomasz): Replace with crbug.com/341902 solution.
+bool IsRecoveryToolRunning(Profile* profile) {
+ extensions::ExtensionPrefs* extension_prefs =
+ extensions::ExtensionPrefs::Get(profile);
+ if (!extension_prefs)
+ return false;
+
+ const std::string kRecoveryToolIds[] = {
+ "kkebgepbbgbcmghedmmdfcbdcodlkngh", // Recovert tool staging
+ "jndclpdbaamdhonoechobihbbiimdgai" // Recovery tool prod
+ };
+
+ for (size_t i = 0; i < arraysize(kRecoveryToolIds); ++i) {
+ const std::string extension_id = kRecoveryToolIds[i];
+ if (extension_prefs->IsExtensionRunning(extension_id))
+ return true;
+ }
+
+ return false;
+}
+
// Sends an event named |event_name| with arguments |event_args| to extensions.
void BroadcastEvent(Profile* profile,
const std::string& event_name,
return file_browser_private::COPY_PROGRESS_STATUS_TYPE_NONE;
}
+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);
+}
+
} // namespace
// Pass dummy value to JobInfo's constructor for make it default constructible.
EventRouter::EventRouter(Profile* profile)
: pref_change_registrar_(new PrefChangeRegistrar),
profile_(profile),
+ multi_user_window_manager_observer_registered_(false),
weak_factory_(this) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
if (volume_manager)
volume_manager->RemoveObserver(this);
+ chrome::MultiUserWindowManager* const multi_user_window_manager =
+ chrome::MultiUserWindowManager::GetInstance();
+ if (multi_user_window_manager &&
+ multi_user_window_manager_observer_registered_) {
+ multi_user_window_manager_observer_registered_ = false;
+ multi_user_window_manager->RemoveObserver(this);
+ }
+
profile_ = NULL;
}
-void EventRouter::ObserveFileSystemEvents() {
+void EventRouter::ObserveEvents() {
if (!profile_) {
NOTREACHED();
return;
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.
iter = drive_jobs_.begin(); iter != drive_jobs_.end(); ++iter) {
linked_ptr<file_browser_private::FileTransferStatus> status(
new file_browser_private::FileTransferStatus());
- JobInfoToTransferStatus(kFileManagerAppId,
+ JobInfoToTransferStatus(profile_,
+ kFileManagerAppId,
iter->second.status,
iter->second.job_info,
status.get());
last_file_transfer_event_ = now;
}
-void EventRouter::OnDirectoryChanged(const base::FilePath& directory_path) {
- HandleFileWatchNotification(directory_path, false);
+void EventRouter::OnDirectoryChanged(const base::FilePath& drive_path) {
+ HandleFileWatchNotification(drive_path, false);
}
-void EventRouter::OnDriveSyncError(
- drive::file_system::DriveSyncErrorType type,
- const base::FilePath& file_path) {
+void EventRouter::OnDriveSyncError(drive::file_system::DriveSyncErrorType type,
+ const base::FilePath& drive_path) {
file_browser_private::DriveSyncErrorEvent event;
switch (type) {
case drive::file_system::DRIVE_SYNC_ERROR_DELETE_WITHOUT_PERMISSION:
file_browser_private::DRIVE_SYNC_ERROR_TYPE_MISC;
break;
}
- event.file_url = util::ConvertRelativeFilePathToFileSystemUrl(
- file_path, kFileManagerAppId).spec();
+ event.file_url = util::ConvertDrivePathToFileSystemUrl(
+ profile_, drive_path, kFileManagerAppId).spec();
BroadcastEvent(
profile_,
file_browser_private::OnDriveSyncError::kEventName,
profile_ != ProfileManager::GetActiveUserProfile())
return;
+ // Do not pop-up the File Manager, if the recovery tool is running.
+ if (IsRecoveryToolRunning(profile_))
+ return;
+
// According to DCF (Design rule of Camera File system) by JEITA / CP-3461
// cameras should have pictures located in the DCIM root directory.
const base::FilePath dcim_path = mount_path.Append(
FILE_PATH_LITERAL("DCIM"));
- // If there is no DCIM folder or an external photo importer is not available,
- // then launch Files.app.
+ // If there is a DCIM folder and Google+ Photos is installed, then do not
+ // launch Files.app.
DirectoryExistsOnUIThread(
dcim_path,
- IsGooglePhotosInstalled(profile_) ?
- base::Bind(&base::DoNothing) :
- base::Bind(&util::OpenRemovableDrive, profile_, mount_path),
+ IsGooglePhotosInstalled(profile_)
+ ? base::Bind(&base::DoNothing)
+ : base::Bind(&util::OpenRemovableDrive, profile_, mount_path),
base::Bind(&util::OpenRemovableDrive, profile_, mount_path));
}
device_path);
}
+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_);
+
+ BroadcastEvent(profile_,
+ file_browser_private::OnProfileAdded::kEventName,
+ file_browser_private::OnProfileAdded::Create());
+ }
+}
+
+void EventRouter::RegisterMultiUserWindowManagerObserver() {
+ if (multi_user_window_manager_observer_registered_)
+ return;
+ chrome::MultiUserWindowManager* const multi_user_window_manager =
+ chrome::MultiUserWindowManager::GetInstance();
+ if (multi_user_window_manager) {
+ multi_user_window_manager->AddObserver(this);
+ multi_user_window_manager_observer_registered_ = true;
+ }
+}
+
+void EventRouter::OnOwnerEntryChanged(aura::Window* window) {
+ BroadcastEvent(profile_,
+ file_browser_private::OnDesktopChanged::kEventName,
+ file_browser_private::OnDesktopChanged::Create());
+}
+
} // namespace file_manager