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

Side by Side Diff: chrome/browser/extensions/api/sync_file_system/sync_file_system_api.cc

Issue 22810002: SyncFS: Reorder initialization sequence of SyncFileSystemService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 3 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 | Annotate | Revision Log
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/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
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 // SyncFileSystem initialization is done in OpenFileSystem below, but we call
113 // GetSyncFileSystemService here too to initialize sync event observer for
114 // extensions API.
115 GetSyncFileSystemService(profile());
116
112 // Initializes sync context for this extension and continue to open 117 // Initializes sync context for this extension and continue to open
113 // a new file system. 118 // a new file system.
114 GetSyncFileSystemService(profile())-> 119 BrowserThread::PostTask(
115 InitializeForApp( 120 BrowserThread::IO, FROM_HERE,
116 GetFileSystemContext(), 121 Bind(&fileapi::FileSystemContext::OpenFileSystem,
117 source_url().GetOrigin(), 122 GetFileSystemContext(),
118 base::Bind(&self::DidInitializeFileSystemContext, this)); 123 source_url().GetOrigin(),
124 fileapi::kFileSystemTypeSyncable,
125 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
126 base::Bind(&self::DidOpenFileSystem, this)));
119 return true; 127 return true;
120 } 128 }
121 129
122 fileapi::FileSystemContext* 130 fileapi::FileSystemContext*
123 SyncFileSystemRequestFileSystemFunction::GetFileSystemContext() { 131 SyncFileSystemRequestFileSystemFunction::GetFileSystemContext() {
124 DCHECK(render_view_host()); 132 DCHECK(render_view_host());
125 return BrowserContext::GetStoragePartition( 133 return BrowserContext::GetStoragePartition(
126 profile(), 134 profile(),
127 render_view_host()->GetSiteInstance())->GetFileSystemContext(); 135 render_view_host()->GetSiteInstance())->GetFileSystemContext();
128 } 136 }
129 137
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( 138 void SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem(
154 base::PlatformFileError error, 139 base::PlatformFileError error,
155 const std::string& file_system_name, 140 const std::string& file_system_name,
156 const GURL& root_url) { 141 const GURL& root_url) {
157 // Repost to switch from IO thread to UI thread for SendResponse(). 142 // Repost to switch from IO thread to UI thread for SendResponse().
158 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 143 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
160 BrowserThread::PostTask( 145 BrowserThread::PostTask(
161 BrowserThread::UI, FROM_HERE, 146 BrowserThread::UI, FROM_HERE,
162 Bind(&SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem, 147 Bind(&SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem,
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 372
388 bool SyncFileSystemGetServiceStatusFunction::RunImpl() { 373 bool SyncFileSystemGetServiceStatusFunction::RunImpl() {
389 sync_file_system::SyncFileSystemService* service = GetSyncFileSystemService( 374 sync_file_system::SyncFileSystemService* service = GetSyncFileSystemService(
390 profile()); 375 profile());
391 results_ = api::sync_file_system::GetServiceStatus::Results::Create( 376 results_ = api::sync_file_system::GetServiceStatus::Results::Create(
392 SyncServiceStateToExtensionEnum(service->GetSyncServiceState())); 377 SyncServiceStateToExtensionEnum(service->GetSyncServiceState()));
393 return true; 378 return true;
394 } 379 }
395 380
396 } // namespace extensions 381 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698