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

Side by Side Diff: chrome/browser/chromeos/extensions/file_browser_event_router.cc

Issue 10834115: Drive: Mount/Unmount GoogleDrive on Files App when the file system is mounted/unmounted. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add a comment. Created 8 years, 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_browser_event_router.h" 5 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 if (iter == file_watchers_.end()) 219 if (iter == file_watchers_.end())
220 return; 220 return;
221 // Remove the renderer process for this watch. 221 // Remove the renderer process for this watch.
222 iter->second->RemoveExtension(extension_id); 222 iter->second->RemoveExtension(extension_id);
223 if (iter->second->GetRefCount() == 0) { 223 if (iter->second->GetRefCount() == 0) {
224 delete iter->second; 224 delete iter->second;
225 file_watchers_.erase(iter); 225 file_watchers_.erase(iter);
226 } 226 }
227 } 227 }
228 228
229 void FileBrowserEventRouter::MountDrive(
230 const base::Closure& callback) {
231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
232
233 gdata::GDataSystemService* system_service =
234 gdata::GDataSystemServiceFactory::GetForProfile(profile_);
235 if (system_service) {
236 system_service->docs_service()->Authenticate(
237 base::Bind(&FileBrowserEventRouter::OnDriveAuthentication,
satorux1 2012/08/02 01:13:05 OnAuthenticated
yoshiki 2012/08/02 05:53:42 Done.
238 this,
239 callback));
240 }
241 }
242
243 void FileBrowserEventRouter::OnDriveAuthentication(
244 const base::Closure& callback,
245 gdata::GDataErrorCode error,
246 const std::string& token) {
247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
248
249 chromeos::MountError error_code;
250 // For the file manager to work offline, GDATA_NO_CONNECTION is allowed.
251 if (error == gdata::HTTP_SUCCESS || error == gdata::GDATA_NO_CONNECTION)
252 error_code = chromeos::MOUNT_ERROR_NONE;
253 else
254 error_code = chromeos::MOUNT_ERROR_NOT_AUTHENTICATED;
255
256 // Pass back the gdata mount point path as source path.
257 const std::string& gdata_path = gdata::util::GetGDataMountPointPathAsString();
258 DiskMountManager::MountPointInfo mount_info(
259 gdata_path,
260 gdata_path,
261 chromeos::MOUNT_TYPE_GDATA,
262 chromeos::disks::MOUNT_CONDITION_NONE);
263
264 // Raise mount event.
265 MountCompleted(DiskMountManager::MOUNTING, error_code, mount_info);
266
267 if (!callback.is_null())
268 callback.Run();
269 }
270
229 void FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread(bool start) { 271 void FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread(bool start) {
230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
231 273
232 gdata::GDataFileSystemInterface* file_system = GetRemoteFileSystem(); 274 gdata::GDataFileSystemInterface* file_system = GetRemoteFileSystem();
233 DCHECK(file_system); 275 DCHECK(file_system);
234 276
235 if (start) { 277 if (start) {
236 file_system->CheckForUpdates(); 278 file_system->CheckForUpdates();
237 if (num_remote_update_requests_ == 0) 279 if (num_remote_update_requests_ == 0)
238 file_system->StartUpdates(); 280 file_system->StartUpdates();
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 args.Append(base::Value::CreateIntegerValue(num_accumulated_entries)); 451 args.Append(base::Value::CreateIntegerValue(num_accumulated_entries));
410 std::string args_json; 452 std::string args_json;
411 base::JSONWriter::Write(&args, &args_json); 453 base::JSONWriter::Write(&args, &args_json);
412 454
413 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 455 profile_->GetExtensionEventRouter()->DispatchEventToExtension(
414 std::string(kFileBrowserDomain), 456 std::string(kFileBrowserDomain),
415 extensions::event_names::kOnDocumentFeedFetched, args_json, 457 extensions::event_names::kOnDocumentFeedFetched, args_json,
416 NULL, GURL()); 458 NULL, GURL());
417 } 459 }
418 460
461 void FileBrowserEventRouter::OnFileSystemMounted() {
462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
463
464 MountDrive(base::Bind(&base::DoNothing)); // Callback does nothing.
465 }
466
467 void FileBrowserEventRouter::OnFileSystemUnmounting() {
468 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
469
470 // Raise a MountCompleted event to notify the File Manager.
471 const std::string& gdata_path = gdata::util::GetGDataMountPointPathAsString();
472 DiskMountManager::MountPointInfo mount_info(
473 gdata_path,
474 gdata_path,
475 chromeos::MOUNT_TYPE_GDATA,
476 chromeos::disks::MOUNT_CONDITION_NONE);
477 MountCompleted(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE,
478 mount_info);
479 }
480
419 void FileBrowserEventRouter::OnAuthenticationFailed() { 481 void FileBrowserEventRouter::OnAuthenticationFailed() {
420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
421 483
422 // Raise a MountCompleted event to notify the File Manager. 484 // Raise a MountCompleted event to notify the File Manager.
423 const std::string& gdata_path = gdata::util::GetGDataMountPointPathAsString(); 485 const std::string& gdata_path = gdata::util::GetGDataMountPointPathAsString();
424 DiskMountManager::MountPointInfo mount_info( 486 DiskMountManager::MountPointInfo mount_info(
425 gdata_path, 487 gdata_path,
426 gdata_path, 488 gdata_path,
427 chromeos::MOUNT_TYPE_GDATA, 489 chromeos::MOUNT_TYPE_GDATA,
428 chromeos::disks::MOUNT_CONDITION_NONE); 490 chromeos::disks::MOUNT_CONDITION_NONE);
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 return scoped_refptr<RefcountedProfileKeyedService>( 874 return scoped_refptr<RefcountedProfileKeyedService>(
813 new FileBrowserEventRouter(profile)); 875 new FileBrowserEventRouter(profile));
814 } 876 }
815 877
816 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { 878 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() {
817 // Explicitly and always allow this router in guest login mode. see 879 // Explicitly and always allow this router in guest login mode. see
818 // chrome/browser/profiles/profile_keyed_base_factory.h comment 880 // chrome/browser/profiles/profile_keyed_base_factory.h comment
819 // for the details. 881 // for the details.
820 return true; 882 return true;
821 } 883 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698