Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/event_router.cc

Issue 566433004: Add notification and observer to copy the file between other users. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/chromeos/extensions/file_manager/event_router.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h" 5 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_change_registrar.h" 10 #include "base/prefs/pref_change_registrar.h"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 return "SecurityError"; 262 return "SecurityError";
263 case base::File::FILE_ERROR_NO_SPACE: 263 case base::File::FILE_ERROR_NO_SPACE:
264 return "QuotaExceededError"; 264 return "QuotaExceededError";
265 case base::File::FILE_ERROR_INVALID_URL: 265 case base::File::FILE_ERROR_INVALID_URL:
266 return "EncodingError"; 266 return "EncodingError";
267 default: 267 default:
268 return "InvalidModificationError"; 268 return "InvalidModificationError";
269 } 269 }
270 } 270 }
271 271
272 void GrantAccessForAddedProfileToRunningInstance(Profile* added_profile,
273 Profile* running_profile) {
274 extensions::ProcessManager* const process_manager =
275 extensions::ExtensionSystem::Get(running_profile)->process_manager();
276 if (!process_manager)
277 return;
278
279 extensions::ExtensionHost* const extension_host =
280 process_manager->GetBackgroundHostForExtension(kFileManagerAppId);
281 if (!extension_host || !extension_host->render_process_host())
282 return;
283
284 const int id = extension_host->render_process_host()->GetID();
285 file_manager::util::SetupProfileFileAccessPermissions(id, added_profile);
286 }
287
272 // Checks if we should send a progress event or not according to the 288 // Checks if we should send a progress event or not according to the
273 // |last_time| of sending an event. If |always| is true, the function always 289 // |last_time| of sending an event. If |always| is true, the function always
274 // returns true. If the function returns true, the function also updates 290 // returns true. If the function returns true, the function also updates
275 // |last_time|. 291 // |last_time|.
276 bool ShouldSendProgressEvent(bool always, base::Time* last_time) { 292 bool ShouldSendProgressEvent(bool always, base::Time* last_time) {
277 const base::Time now = base::Time::Now(); 293 const base::Time now = base::Time::Now();
278 const int64 delta = (now - *last_time).InMilliseconds(); 294 const int64 delta = (now - *last_time).InMilliseconds();
279 // delta < 0 may rarely happen if system clock is synced and rewinded. 295 // delta < 0 may rarely happen if system clock is synced and rewinded.
280 // To be conservative, we don't skip in that case. 296 // To be conservative, we don't skip in that case.
281 if (!always && 0 <= delta && delta < kProgressEventFrequencyInMilliseconds) { 297 if (!always && 0 <= delta && delta < kProgressEventFrequencyInMilliseconds) {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 } 473 }
458 474
459 pref_change_registrar_->Init(profile_->GetPrefs()); 475 pref_change_registrar_->Init(profile_->GetPrefs());
460 base::Closure callback = 476 base::Closure callback =
461 base::Bind(&EventRouter::OnFileManagerPrefsChanged, 477 base::Bind(&EventRouter::OnFileManagerPrefsChanged,
462 weak_factory_.GetWeakPtr()); 478 weak_factory_.GetWeakPtr());
463 pref_change_registrar_->Add(prefs::kDisableDriveOverCellular, callback); 479 pref_change_registrar_->Add(prefs::kDisableDriveOverCellular, callback);
464 pref_change_registrar_->Add(prefs::kDisableDriveHostedFiles, callback); 480 pref_change_registrar_->Add(prefs::kDisableDriveHostedFiles, callback);
465 pref_change_registrar_->Add(prefs::kDisableDrive, callback); 481 pref_change_registrar_->Add(prefs::kDisableDrive, callback);
466 pref_change_registrar_->Add(prefs::kUse24HourClock, callback); 482 pref_change_registrar_->Add(prefs::kUse24HourClock, callback);
483
484 notification_registrar_.Add(this,
485 chrome::NOTIFICATION_PROFILE_ADDED,
486 content::NotificationService::AllSources());
467 } 487 }
468 488
469 // File watch setup routines. 489 // File watch setup routines.
470 void EventRouter::AddFileWatch(const base::FilePath& local_path, 490 void EventRouter::AddFileWatch(const base::FilePath& local_path,
471 const base::FilePath& virtual_path, 491 const base::FilePath& virtual_path,
472 const std::string& extension_id, 492 const std::string& extension_id,
473 const BoolCallback& callback) { 493 const BoolCallback& callback) {
474 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
475 DCHECK(!callback.is_null()); 495 DCHECK(!callback.is_null());
476 496
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 949 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
930 // Do nothing. 950 // Do nothing.
931 } 951 }
932 952
933 void EventRouter::OnFormatCompleted(const std::string& device_path, 953 void EventRouter::OnFormatCompleted(const std::string& device_path,
934 bool success) { 954 bool success) {
935 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 955 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
936 // Do nothing. 956 // Do nothing.
937 } 957 }
938 958
959 void EventRouter::Observe(int type,
960 const content::NotificationSource& source,
961 const content::NotificationDetails& details) {
962 if (type == chrome::NOTIFICATION_PROFILE_ADDED) {
963 Profile* const added_profile = content::Source<Profile>(source).ptr();
964 if (!added_profile->IsOffTheRecord())
965 GrantAccessForAddedProfileToRunningInstance(added_profile, profile_);
966 }
967 }
968
939 } // namespace file_manager 969 } // namespace file_manager
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/file_manager/event_router.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698