OLD | NEW |
---|---|
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 Loading... | |
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::MountGData( | |
230 const base::Callback<void(bool)>& callback) { | |
satorux1
2012/08/01 20:59:01
add DCHECK(BrowserThread::CurrentlyOn(BrowserThrea
yoshiki
2012/08/01 22:23:39
Done.
| |
231 gdata::GDataSystemService* system_service = | |
232 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | |
233 if (system_service) { | |
234 system_service->docs_service()->Authenticate( | |
235 base::Bind(&FileBrowserEventRouter::OnGDataAuthentication, | |
236 this, | |
237 callback)); | |
238 } | |
239 } | |
240 | |
241 void FileBrowserEventRouter::OnGDataAuthentication( | |
242 const base::Callback<void(bool)>& callback, | |
243 gdata::GDataErrorCode error, | |
244 const std::string& token) { | |
satorux1
2012/08/01 20:59:01
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::U
yoshiki
2012/08/01 22:23:39
Done.
| |
245 chromeos::MountError error_code; | |
246 // For the file manager to work offline, GDATA_NO_CONNECTION is allowed. | |
247 if (error == gdata::HTTP_SUCCESS || error == gdata::GDATA_NO_CONNECTION) | |
248 error_code = chromeos::MOUNT_ERROR_NONE; | |
249 else | |
250 error_code = chromeos::MOUNT_ERROR_NOT_AUTHENTICATED; | |
251 | |
252 // Pass back the gdata mount point path as source path. | |
253 const std::string& gdata_path = gdata::util::GetGDataMountPointPathAsString(); | |
254 DiskMountManager::MountPointInfo mount_info( | |
255 gdata_path, | |
256 gdata_path, | |
257 chromeos::MOUNT_TYPE_GDATA, | |
258 chromeos::disks::MOUNT_CONDITION_NONE); | |
259 | |
260 // Raise mount event. | |
261 MountCompleted(DiskMountManager::MOUNTING, error_code, mount_info); | |
262 | |
263 if (!callback.is_null()) | |
264 callback.Run(true); | |
265 } | |
266 | |
229 void FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread(bool start) { | 267 void FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread(bool start) { |
230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
231 | 269 |
232 gdata::GDataFileSystemInterface* file_system = GetRemoteFileSystem(); | 270 gdata::GDataFileSystemInterface* file_system = GetRemoteFileSystem(); |
233 DCHECK(file_system); | 271 DCHECK(file_system); |
234 | 272 |
235 if (start) { | 273 if (start) { |
236 file_system->CheckForUpdates(); | 274 file_system->CheckForUpdates(); |
237 if (num_remote_update_requests_ == 0) | 275 if (num_remote_update_requests_ == 0) |
238 file_system->StartUpdates(); | 276 file_system->StartUpdates(); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
409 args.Append(base::Value::CreateIntegerValue(num_accumulated_entries)); | 447 args.Append(base::Value::CreateIntegerValue(num_accumulated_entries)); |
410 std::string args_json; | 448 std::string args_json; |
411 base::JSONWriter::Write(&args, &args_json); | 449 base::JSONWriter::Write(&args, &args_json); |
412 | 450 |
413 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 451 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
414 std::string(kFileBrowserDomain), | 452 std::string(kFileBrowserDomain), |
415 extensions::event_names::kOnDocumentFeedFetched, args_json, | 453 extensions::event_names::kOnDocumentFeedFetched, args_json, |
416 NULL, GURL()); | 454 NULL, GURL()); |
417 } | 455 } |
418 | 456 |
457 void FileBrowserEventRouter::OnFileSystemMounted() { | |
458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
459 MountGData(base::Callback<void(bool)>()); // Callback does nothing. | |
460 } | |
461 | |
462 void FileBrowserEventRouter::OnFileSystemUnmounting() { | |
463 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
464 | |
465 // Raise a MountCompleted event to notify the File Manager. | |
466 const std::string& gdata_path = gdata::util::GetGDataMountPointPathAsString(); | |
467 DiskMountManager::MountPointInfo mount_info( | |
468 gdata_path, | |
469 gdata_path, | |
470 chromeos::MOUNT_TYPE_GDATA, | |
471 chromeos::disks::MOUNT_CONDITION_NONE); | |
472 MountCompleted(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE, | |
473 mount_info); | |
474 } | |
475 | |
419 void FileBrowserEventRouter::OnAuthenticationFailed() { | 476 void FileBrowserEventRouter::OnAuthenticationFailed() { |
420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 477 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
421 | 478 |
422 // Raise a MountCompleted event to notify the File Manager. | 479 // Raise a MountCompleted event to notify the File Manager. |
423 const std::string& gdata_path = gdata::util::GetGDataMountPointPathAsString(); | 480 const std::string& gdata_path = gdata::util::GetGDataMountPointPathAsString(); |
424 DiskMountManager::MountPointInfo mount_info( | 481 DiskMountManager::MountPointInfo mount_info( |
425 gdata_path, | 482 gdata_path, |
426 gdata_path, | 483 gdata_path, |
427 chromeos::MOUNT_TYPE_GDATA, | 484 chromeos::MOUNT_TYPE_GDATA, |
428 chromeos::disks::MOUNT_CONDITION_NONE); | 485 chromeos::disks::MOUNT_CONDITION_NONE); |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
812 return scoped_refptr<RefcountedProfileKeyedService>( | 869 return scoped_refptr<RefcountedProfileKeyedService>( |
813 new FileBrowserEventRouter(profile)); | 870 new FileBrowserEventRouter(profile)); |
814 } | 871 } |
815 | 872 |
816 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { | 873 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { |
817 // Explicitly and always allow this router in guest login mode. see | 874 // Explicitly and always allow this router in guest login mode. see |
818 // chrome/browser/profiles/profile_keyed_base_factory.h comment | 875 // chrome/browser/profiles/profile_keyed_base_factory.h comment |
819 // for the details. | 876 // for the details. |
820 return true; | 877 return true; |
821 } | 878 } |
OLD | NEW |