Chromium Code Reviews| 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/extensions/api/sync_file_system/sync_file_system_api.h" | 5 #include "chrome/browser/extensions/api/sync_file_system/sync_file_system_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 SetResult(new base::FundamentalValue(false)); | 102 SetResult(new base::FundamentalValue(false)); |
| 103 SendResponse(false); | 103 SendResponse(false); |
| 104 return; | 104 return; |
| 105 } | 105 } |
| 106 | 106 |
| 107 SetResult(new base::FundamentalValue(true)); | 107 SetResult(new base::FundamentalValue(true)); |
| 108 SendResponse(true); | 108 SendResponse(true); |
| 109 } | 109 } |
| 110 | 110 |
| 111 bool SyncFileSystemRequestFileSystemFunction::RunImpl() { | 111 bool SyncFileSystemRequestFileSystemFunction::RunImpl() { |
| 112 // Initializes observer of sync events in SyncFileSystem. | |
|
kinuko
2013/08/29 08:28:21
Can you elaborate a little more:
// SyncFileSystem
nhiroki
2013/08/29 08:43:35
Done.
| |
| 113 GetSyncFileSystemService(profile()); | |
| 114 | |
| 112 // Initializes sync context for this extension and continue to open | 115 // Initializes sync context for this extension and continue to open |
| 113 // a new file system. | 116 // a new file system. |
| 114 GetSyncFileSystemService(profile())-> | 117 BrowserThread::PostTask( |
| 115 InitializeForApp( | 118 BrowserThread::IO, FROM_HERE, |
| 116 GetFileSystemContext(), | 119 Bind(&fileapi::FileSystemContext::OpenFileSystem, |
| 117 source_url().GetOrigin(), | 120 GetFileSystemContext(), |
| 118 base::Bind(&self::DidInitializeFileSystemContext, this)); | 121 source_url().GetOrigin(), |
| 122 fileapi::kFileSystemTypeSyncable, | |
| 123 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | |
| 124 base::Bind(&self::DidOpenFileSystem, this))); | |
| 119 return true; | 125 return true; |
| 120 } | 126 } |
| 121 | 127 |
| 122 fileapi::FileSystemContext* | 128 fileapi::FileSystemContext* |
| 123 SyncFileSystemRequestFileSystemFunction::GetFileSystemContext() { | 129 SyncFileSystemRequestFileSystemFunction::GetFileSystemContext() { |
| 124 DCHECK(render_view_host()); | 130 DCHECK(render_view_host()); |
| 125 return BrowserContext::GetStoragePartition( | 131 return BrowserContext::GetStoragePartition( |
| 126 profile(), | 132 profile(), |
| 127 render_view_host()->GetSiteInstance())->GetFileSystemContext(); | 133 render_view_host()->GetSiteInstance())->GetFileSystemContext(); |
| 128 } | 134 } |
| 129 | 135 |
| 130 void SyncFileSystemRequestFileSystemFunction::DidInitializeFileSystemContext( | |
| 131 SyncStatusCode status) { | |
| 132 if (status != sync_file_system::SYNC_STATUS_OK) { | |
| 133 error_ = sync_file_system::SyncStatusCodeToString(status); | |
| 134 SendResponse(false); | |
| 135 return; | |
| 136 } | |
| 137 | |
| 138 if (!render_view_host()) { | |
| 139 // The app seems to have been closed. | |
| 140 return; | |
| 141 } | |
| 142 | |
| 143 BrowserThread::PostTask( | |
| 144 BrowserThread::IO, FROM_HERE, | |
| 145 Bind(&fileapi::FileSystemContext::OpenFileSystem, | |
| 146 GetFileSystemContext(), | |
| 147 source_url().GetOrigin(), | |
| 148 fileapi::kFileSystemTypeSyncable, | |
| 149 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | |
| 150 base::Bind(&self::DidOpenFileSystem, this))); | |
| 151 } | |
| 152 | |
| 153 void SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem( | 136 void SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem( |
| 154 base::PlatformFileError error, | 137 base::PlatformFileError error, |
| 155 const std::string& file_system_name, | 138 const std::string& file_system_name, |
| 156 const GURL& root_url) { | 139 const GURL& root_url) { |
| 157 // Repost to switch from IO thread to UI thread for SendResponse(). | 140 // Repost to switch from IO thread to UI thread for SendResponse(). |
| 158 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 141 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 160 BrowserThread::PostTask( | 143 BrowserThread::PostTask( |
| 161 BrowserThread::UI, FROM_HERE, | 144 BrowserThread::UI, FROM_HERE, |
| 162 Bind(&SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem, | 145 Bind(&SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem, |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 DCHECK(service); | 362 DCHECK(service); |
| 380 api::sync_file_system::ConflictResolutionPolicy policy = | 363 api::sync_file_system::ConflictResolutionPolicy policy = |
| 381 ConflictResolutionPolicyToExtensionEnum( | 364 ConflictResolutionPolicyToExtensionEnum( |
| 382 service->GetConflictResolutionPolicy()); | 365 service->GetConflictResolutionPolicy()); |
| 383 SetResult(new base::StringValue( | 366 SetResult(new base::StringValue( |
| 384 api::sync_file_system::ToString(policy))); | 367 api::sync_file_system::ToString(policy))); |
| 385 return true; | 368 return true; |
| 386 } | 369 } |
| 387 | 370 |
| 388 } // namespace extensions | 371 } // namespace extensions |
| OLD | NEW |