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 <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); | 74 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); |
75 | 75 |
76 scoped_refptr<storage::FileSystemContext> file_system_context = | 76 scoped_refptr<storage::FileSystemContext> file_system_context = |
77 BrowserContext::GetStoragePartition( | 77 BrowserContext::GetStoragePartition( |
78 GetProfile(), render_frame_host()->GetSiteInstance()) | 78 GetProfile(), render_frame_host()->GetSiteInstance()) |
79 ->GetFileSystemContext(); | 79 ->GetFileSystemContext(); |
80 storage::FileSystemURL file_system_url( | 80 storage::FileSystemURL file_system_url( |
81 file_system_context->CrackURL(GURL(url))); | 81 file_system_context->CrackURL(GURL(url))); |
82 | 82 |
83 BrowserThread::PostTask( | 83 BrowserThread::PostTask( |
84 BrowserThread::IO, | 84 BrowserThread::IO, FROM_HERE, |
85 FROM_HERE, | 85 BindOnce( |
86 Bind(&storage::FileSystemContext::DeleteFileSystem, | 86 &storage::FileSystemContext::DeleteFileSystem, file_system_context, |
87 file_system_context, | 87 source_url().GetOrigin(), file_system_url.type(), |
88 source_url().GetOrigin(), | 88 Bind(&SyncFileSystemDeleteFileSystemFunction::DidDeleteFileSystem, |
89 file_system_url.type(), | 89 this))); |
90 Bind(&SyncFileSystemDeleteFileSystemFunction::DidDeleteFileSystem, | |
91 this))); | |
92 return true; | 90 return true; |
93 } | 91 } |
94 | 92 |
95 void SyncFileSystemDeleteFileSystemFunction::DidDeleteFileSystem( | 93 void SyncFileSystemDeleteFileSystemFunction::DidDeleteFileSystem( |
96 base::File::Error error) { | 94 base::File::Error error) { |
97 // Repost to switch from IO thread to UI thread for SendResponse(). | 95 // Repost to switch from IO thread to UI thread for SendResponse(). |
98 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 96 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
99 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 97 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
100 BrowserThread::PostTask( | 98 BrowserThread::PostTask( |
101 BrowserThread::UI, | 99 BrowserThread::UI, FROM_HERE, |
102 FROM_HERE, | 100 BindOnce(&SyncFileSystemDeleteFileSystemFunction::DidDeleteFileSystem, |
103 Bind(&SyncFileSystemDeleteFileSystemFunction::DidDeleteFileSystem, this, | 101 this, error)); |
104 error)); | |
105 return; | 102 return; |
106 } | 103 } |
107 | 104 |
108 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 105 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
109 if (error != base::File::FILE_OK) { | 106 if (error != base::File::FILE_OK) { |
110 error_ = ErrorToString(sync_file_system::FileErrorToSyncStatusCode(error)); | 107 error_ = ErrorToString(sync_file_system::FileErrorToSyncStatusCode(error)); |
111 SetResult(base::MakeUnique<base::Value>(false)); | 108 SetResult(base::MakeUnique<base::Value>(false)); |
112 SendResponse(false); | 109 SendResponse(false); |
113 return; | 110 return; |
114 } | 111 } |
115 | 112 |
116 SetResult(base::MakeUnique<base::Value>(true)); | 113 SetResult(base::MakeUnique<base::Value>(true)); |
117 SendResponse(true); | 114 SendResponse(true); |
118 } | 115 } |
119 | 116 |
120 bool SyncFileSystemRequestFileSystemFunction::RunAsync() { | 117 bool SyncFileSystemRequestFileSystemFunction::RunAsync() { |
121 // SyncFileSystem initialization is done in OpenFileSystem below, but we call | 118 // SyncFileSystem initialization is done in OpenFileSystem below, but we call |
122 // GetSyncFileSystemService here too to initialize sync event observer for | 119 // GetSyncFileSystemService here too to initialize sync event observer for |
123 // extensions API. | 120 // extensions API. |
124 if (!GetSyncFileSystemService(GetProfile())) | 121 if (!GetSyncFileSystemService(GetProfile())) |
125 return false; | 122 return false; |
126 | 123 |
127 // Initializes sync context for this extension and continue to open | 124 // Initializes sync context for this extension and continue to open |
128 // a new file system. | 125 // a new file system. |
129 BrowserThread::PostTask(BrowserThread::IO, | 126 BrowserThread::PostTask( |
130 FROM_HERE, | 127 BrowserThread::IO, FROM_HERE, |
131 Bind(&storage::FileSystemContext::OpenFileSystem, | 128 BindOnce(&storage::FileSystemContext::OpenFileSystem, |
132 GetFileSystemContext(), | 129 GetFileSystemContext(), source_url().GetOrigin(), |
133 source_url().GetOrigin(), | 130 storage::kFileSystemTypeSyncable, |
134 storage::kFileSystemTypeSyncable, | 131 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
135 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 132 base::Bind(&self::DidOpenFileSystem, this))); |
136 base::Bind(&self::DidOpenFileSystem, this))); | |
137 return true; | 133 return true; |
138 } | 134 } |
139 | 135 |
140 storage::FileSystemContext* | 136 storage::FileSystemContext* |
141 SyncFileSystemRequestFileSystemFunction::GetFileSystemContext() { | 137 SyncFileSystemRequestFileSystemFunction::GetFileSystemContext() { |
142 DCHECK(render_frame_host()); | 138 DCHECK(render_frame_host()); |
143 return BrowserContext::GetStoragePartition( | 139 return BrowserContext::GetStoragePartition( |
144 GetProfile(), render_frame_host()->GetSiteInstance()) | 140 GetProfile(), render_frame_host()->GetSiteInstance()) |
145 ->GetFileSystemContext(); | 141 ->GetFileSystemContext(); |
146 } | 142 } |
147 | 143 |
148 void SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem( | 144 void SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem( |
149 const GURL& root_url, | 145 const GURL& root_url, |
150 const std::string& file_system_name, | 146 const std::string& file_system_name, |
151 base::File::Error error) { | 147 base::File::Error error) { |
152 // Repost to switch from IO thread to UI thread for SendResponse(). | 148 // Repost to switch from IO thread to UI thread for SendResponse(). |
153 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 149 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
154 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 150 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
155 BrowserThread::PostTask( | 151 BrowserThread::PostTask( |
156 BrowserThread::UI, FROM_HERE, | 152 BrowserThread::UI, FROM_HERE, |
157 Bind(&SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem, | 153 BindOnce(&SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem, |
158 this, root_url, file_system_name, error)); | 154 this, root_url, file_system_name, error)); |
159 return; | 155 return; |
160 } | 156 } |
161 | 157 |
162 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 158 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
163 if (error != base::File::FILE_OK) { | 159 if (error != base::File::FILE_OK) { |
164 error_ = ErrorToString(sync_file_system::FileErrorToSyncStatusCode(error)); | 160 error_ = ErrorToString(sync_file_system::FileErrorToSyncStatusCode(error)); |
165 SendResponse(false); | 161 SendResponse(false); |
166 return; | 162 return; |
167 } | 163 } |
168 | 164 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 ->GetFileSystemContext(); | 304 ->GetFileSystemContext(); |
309 storage::FileSystemURL file_system_url( | 305 storage::FileSystemURL file_system_url( |
310 file_system_context->CrackURL(GURL(url))); | 306 file_system_context->CrackURL(GURL(url))); |
311 | 307 |
312 scoped_refptr<storage::QuotaManager> quota_manager = | 308 scoped_refptr<storage::QuotaManager> quota_manager = |
313 BrowserContext::GetStoragePartition( | 309 BrowserContext::GetStoragePartition( |
314 GetProfile(), render_frame_host()->GetSiteInstance()) | 310 GetProfile(), render_frame_host()->GetSiteInstance()) |
315 ->GetQuotaManager(); | 311 ->GetQuotaManager(); |
316 | 312 |
317 BrowserThread::PostTask( | 313 BrowserThread::PostTask( |
318 BrowserThread::IO, | 314 BrowserThread::IO, FROM_HERE, |
319 FROM_HERE, | 315 BindOnce( |
320 Bind(&storage::QuotaManager::GetUsageAndQuotaForWebApps, | 316 &storage::QuotaManager::GetUsageAndQuotaForWebApps, quota_manager, |
321 quota_manager, | 317 source_url().GetOrigin(), |
322 source_url().GetOrigin(), | 318 storage::FileSystemTypeToQuotaStorageType(file_system_url.type()), |
323 storage::FileSystemTypeToQuotaStorageType(file_system_url.type()), | 319 Bind(&SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota, |
324 Bind(&SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota, | 320 this))); |
325 this))); | |
326 | 321 |
327 return true; | 322 return true; |
328 } | 323 } |
329 | 324 |
330 void SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota( | 325 void SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota( |
331 storage::QuotaStatusCode status, | 326 storage::QuotaStatusCode status, |
332 int64_t usage, | 327 int64_t usage, |
333 int64_t quota) { | 328 int64_t quota) { |
334 // Repost to switch from IO thread to UI thread for SendResponse(). | 329 // Repost to switch from IO thread to UI thread for SendResponse(). |
335 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 330 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
336 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 331 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
337 BrowserThread::PostTask( | 332 BrowserThread::PostTask( |
338 BrowserThread::UI, | 333 BrowserThread::UI, FROM_HERE, |
339 FROM_HERE, | 334 BindOnce(&SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota, |
340 Bind(&SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota, this, | 335 this, status, usage, quota)); |
341 status, usage, quota)); | |
342 return; | 336 return; |
343 } | 337 } |
344 | 338 |
345 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 339 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
346 if (status != storage::kQuotaStatusOk) { | 340 if (status != storage::kQuotaStatusOk) { |
347 error_ = QuotaStatusCodeToString(status); | 341 error_ = QuotaStatusCodeToString(status); |
348 SendResponse(false); | 342 SendResponse(false); |
349 return; | 343 return; |
350 } | 344 } |
351 | 345 |
(...skipping 29 matching lines...) Expand all Loading... |
381 sync_file_system::SyncFileSystemService* service = | 375 sync_file_system::SyncFileSystemService* service = |
382 GetSyncFileSystemService(browser_context()); | 376 GetSyncFileSystemService(browser_context()); |
383 if (!service) | 377 if (!service) |
384 return RespondNow(Error(kUnknownErrorDoNotUse)); | 378 return RespondNow(Error(kUnknownErrorDoNotUse)); |
385 return RespondNow( | 379 return RespondNow( |
386 ArgumentList(api::sync_file_system::GetServiceStatus::Results::Create( | 380 ArgumentList(api::sync_file_system::GetServiceStatus::Results::Create( |
387 SyncServiceStateToExtensionEnum(service->GetSyncServiceState())))); | 381 SyncServiceStateToExtensionEnum(service->GetSyncServiceState())))); |
388 } | 382 } |
389 | 383 |
390 } // namespace extensions | 384 } // namespace extensions |
OLD | NEW |