| 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 GetSyncFileSystemService(profile()); |
| 113 |
| 112 // Initializes sync context for this extension and continue to open | 114 // Initializes sync context for this extension and continue to open |
| 113 // a new file system. | 115 // a new file system. |
| 114 GetSyncFileSystemService(profile())-> | 116 BrowserThread::PostTask( |
| 115 InitializeForApp( | 117 BrowserThread::IO, FROM_HERE, |
| 116 GetFileSystemContext(), | 118 Bind(&fileapi::FileSystemContext::OpenFileSystem, |
| 117 source_url().GetOrigin(), | 119 GetFileSystemContext(), |
| 118 base::Bind(&self::DidInitializeFileSystemContext, this)); | 120 source_url().GetOrigin(), |
| 121 fileapi::kFileSystemTypeSyncable, |
| 122 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 123 base::Bind(&self::DidOpenFileSystem, this))); |
| 119 return true; | 124 return true; |
| 120 } | 125 } |
| 121 | 126 |
| 122 fileapi::FileSystemContext* | 127 fileapi::FileSystemContext* |
| 123 SyncFileSystemRequestFileSystemFunction::GetFileSystemContext() { | 128 SyncFileSystemRequestFileSystemFunction::GetFileSystemContext() { |
| 124 DCHECK(render_view_host()); | 129 DCHECK(render_view_host()); |
| 125 return BrowserContext::GetStoragePartition( | 130 return BrowserContext::GetStoragePartition( |
| 126 profile(), | 131 profile(), |
| 127 render_view_host()->GetSiteInstance())->GetFileSystemContext(); | 132 render_view_host()->GetSiteInstance())->GetFileSystemContext(); |
| 128 } | 133 } |
| 129 | 134 |
| 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( | 135 void SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem( |
| 154 base::PlatformFileError error, | 136 base::PlatformFileError error, |
| 155 const std::string& file_system_name, | 137 const std::string& file_system_name, |
| 156 const GURL& root_url) { | 138 const GURL& root_url) { |
| 157 // Repost to switch from IO thread to UI thread for SendResponse(). | 139 // Repost to switch from IO thread to UI thread for SendResponse(). |
| 158 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 140 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 160 BrowserThread::PostTask( | 142 BrowserThread::PostTask( |
| 161 BrowserThread::UI, FROM_HERE, | 143 BrowserThread::UI, FROM_HERE, |
| 162 Bind(&SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem, | 144 Bind(&SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem, |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 DCHECK(service); | 361 DCHECK(service); |
| 380 api::sync_file_system::ConflictResolutionPolicy policy = | 362 api::sync_file_system::ConflictResolutionPolicy policy = |
| 381 ConflictResolutionPolicyToExtensionEnum( | 363 ConflictResolutionPolicyToExtensionEnum( |
| 382 service->GetConflictResolutionPolicy()); | 364 service->GetConflictResolutionPolicy()); |
| 383 SetResult(new base::StringValue( | 365 SetResult(new base::StringValue( |
| 384 api::sync_file_system::ToString(policy))); | 366 api::sync_file_system::ToString(policy))); |
| 385 return true; | 367 return true; |
| 386 } | 368 } |
| 387 | 369 |
| 388 } // namespace extensions | 370 } // namespace extensions |
| OLD | NEW |