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

Side by Side Diff: chrome/browser/chromeos/extensions/file_browser_private_api.cc

Issue 10391103: [File Manager] Add/remove Google Drive folder in the open File Manager when Drive enabled/disabled … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 7 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/chromeos/extensions/file_browser_private_api.h" 5 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 172
173 173
174 // Gives the extension renderer |host| file |permissions| for the given |path|. 174 // Gives the extension renderer |host| file |permissions| for the given |path|.
175 void GrantFilePermissionsToHost(content::RenderViewHost* host, 175 void GrantFilePermissionsToHost(content::RenderViewHost* host,
176 const FilePath& path, 176 const FilePath& path,
177 int permissions) { 177 int permissions) {
178 ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( 178 ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile(
179 host->GetProcess()->GetID(), path, permissions); 179 host->GetProcess()->GetID(), path, permissions);
180 } 180 }
181 181
182 void AddGDataMountPoint(
183 Profile* profile,
184 const std::string& extension_id,
185 content::RenderViewHost* render_view_host) {
186 fileapi::ExternalFileSystemMountPointProvider* provider =
187 BrowserContext::GetFileSystemContext(profile)->external_provider();
188 const FilePath mount_point = gdata::util::GetGDataMountPointPath();
189 if (!render_view_host || !render_view_host->GetProcess())
190 return;
191 if (!provider || provider->HasMountPoint(mount_point))
192 return;
193
194 // Grant R/W permissions to gdata 'folder'. File API layer still
195 // expects this to be satisfied.
196 GrantFilePermissionsToHost(render_view_host,
197 mount_point,
198 file_handler_util::GetReadWritePermissions());
199
200 // Grant R/W permission for tmp and pinned cache folder.
201 gdata::GDataSystemService* system_service =
202 gdata::GDataSystemServiceFactory::GetForProfile(profile);
203 // |system_service| is NULL if incognito window / guest login.
204 if (!system_service || !system_service->file_system())
205 return;
206 gdata::GDataFileSystem* gdata_file_system = system_service->file_system();
207
208 // We check permissions for raw cache file paths only for read-only
209 // operations (when fileEntry.file() is called), so read only permissions
210 // should be sufficient for all cache paths. For the rest of supported
211 // operations the file access check is done for drive/ paths.
212 GrantFilePermissionsToHost(render_view_host,
213 gdata_file_system->GetCacheDirectoryPath(
214 gdata::GDataRootDirectory::CACHE_TYPE_TMP),
215 file_handler_util::GetReadOnlyPermissions());
216 GrantFilePermissionsToHost(
217 render_view_host,
218 gdata_file_system->GetCacheDirectoryPath(
219 gdata::GDataRootDirectory::CACHE_TYPE_PERSISTENT),
220 file_handler_util::GetReadOnlyPermissions());
221
222 provider->AddRemoteMountPoint(
223 mount_point,
224 new gdata::GDataFileSystemProxy(gdata_file_system));
225
226 FilePath mount_point_virtual;
227 if (provider->GetVirtualPath(mount_point, &mount_point_virtual))
228 provider->GrantFileAccessToExtension(extension_id, mount_point_virtual);
229 }
230
182 // Given a file url, find the virtual FilePath associated with it. 231 // Given a file url, find the virtual FilePath associated with it.
183 FilePath GetVirtualPathFromURL(const GURL& file_url) { 232 FilePath GetVirtualPathFromURL(const GURL& file_url) {
184 FilePath virtual_path; 233 FilePath virtual_path;
185 fileapi::FileSystemType type = fileapi::kFileSystemTypeUnknown; 234 fileapi::FileSystemType type = fileapi::kFileSystemTypeUnknown;
186 GURL file_origin_url; 235 GURL file_origin_url;
187 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, &virtual_path) || 236 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, &virtual_path) ||
188 type != fileapi::kFileSystemTypeExternal) { 237 type != fileapi::kFileSystemTypeExternal) {
189 NOTREACHED(); 238 NOTREACHED();
190 return FilePath(); 239 return FilePath();
191 } 240 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 return true; 370 return true;
322 } 371 }
323 372
324 void RequestLocalFileSystemFunction::RespondSuccessOnUIThread( 373 void RequestLocalFileSystemFunction::RespondSuccessOnUIThread(
325 const std::string& name, const GURL& root_path) { 374 const std::string& name, const GURL& root_path) {
326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
327 // Add gdata mount point immediately when we kick of first instance of file 376 // Add gdata mount point immediately when we kick of first instance of file
328 // manager. The actual mount event will be sent to UI only when we perform 377 // manager. The actual mount event will be sent to UI only when we perform
329 // proper authentication. 378 // proper authentication.
330 if (gdata::util::IsGDataAvailable(profile_)) 379 if (gdata::util::IsGDataAvailable(profile_))
331 AddGDataMountPoint(); 380 AddGDataMountPoint(profile_, extension_id(), render_view_host());
332 result_.reset(new DictionaryValue()); 381 result_.reset(new DictionaryValue());
333 DictionaryValue* dict = reinterpret_cast<DictionaryValue*>(result_.get()); 382 DictionaryValue* dict = reinterpret_cast<DictionaryValue*>(result_.get());
334 dict->SetString("name", name); 383 dict->SetString("name", name);
335 dict->SetString("path", root_path.spec()); 384 dict->SetString("path", root_path.spec());
336 dict->SetInteger("error", base::PLATFORM_FILE_OK); 385 dict->SetInteger("error", base::PLATFORM_FILE_OK);
337 SendResponse(true); 386 SendResponse(true);
338 } 387 }
339 388
340 void RequestLocalFileSystemFunction::AddGDataMountPoint() {
341 fileapi::ExternalFileSystemMountPointProvider* provider =
342 BrowserContext::GetFileSystemContext(profile_)->external_provider();
343 const FilePath mount_point = gdata::util::GetGDataMountPointPath();
344 if (!render_view_host() || !render_view_host()->GetProcess())
345 return;
346 if (!provider || provider->HasMountPoint(mount_point))
347 return;
348
349 // Grant R/W permissions to gdata 'folder'. File API layer still
350 // expects this to be satisfied.
351 GrantFilePermissionsToHost(render_view_host(),
352 mount_point,
353 file_handler_util::GetReadWritePermissions());
354
355 // Grant R/W permission for tmp and pinned cache folder.
356 gdata::GDataSystemService* system_service =
357 gdata::GDataSystemServiceFactory::GetForProfile(profile_);
358 // |system_service| is NULL if incognito window / guest login.
359 if (!system_service || !system_service->file_system())
360 return;
361 gdata::GDataFileSystem* gdata_file_system = system_service->file_system();
362
363 // We check permissions for raw cache file paths only for read-only
364 // operations (when fileEntry.file() is called), so read only permissions
365 // should be sufficient for all cache paths. For the rest of supported
366 // operations the file access check is done for drive/ paths.
367 GrantFilePermissionsToHost(render_view_host(),
368 gdata_file_system->GetCacheDirectoryPath(
369 gdata::GDataRootDirectory::CACHE_TYPE_TMP),
370 file_handler_util::GetReadOnlyPermissions());
371 GrantFilePermissionsToHost(
372 render_view_host(),
373 gdata_file_system->GetCacheDirectoryPath(
374 gdata::GDataRootDirectory::CACHE_TYPE_PERSISTENT),
375 file_handler_util::GetReadOnlyPermissions());
376
377 provider->AddRemoteMountPoint(
378 mount_point,
379 new gdata::GDataFileSystemProxy(gdata_file_system));
380
381 FilePath mount_point_virtual;
382 if (provider->GetVirtualPath(mount_point, &mount_point_virtual))
383 provider->GrantFileAccessToExtension(extension_id(), mount_point_virtual);
384 }
385
386 void RequestLocalFileSystemFunction::RespondFailedOnUIThread( 389 void RequestLocalFileSystemFunction::RespondFailedOnUIThread(
387 base::PlatformFileError error_code) { 390 base::PlatformFileError error_code) {
388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 391 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
389 error_ = base::StringPrintf(kFileError, static_cast<int>(error_code)); 392 error_ = base::StringPrintf(kFileError, static_cast<int>(error_code));
390 SendResponse(false); 393 SendResponse(false);
391 } 394 }
392 395
393 bool FileWatchBrowserFunctionBase::GetLocalFilePath( 396 bool FileWatchBrowserFunctionBase::GetLocalFilePath(
394 const GURL& file_url, FilePath* local_path, FilePath* virtual_path) { 397 const GURL& file_url, FilePath* local_path, FilePath* virtual_path) {
395 GURL file_origin_url; 398 GURL file_origin_url;
(...skipping 1628 matching lines...) Expand 10 before | Expand all | Expand 10 after
2024 SendResponse(false); 2027 SendResponse(false);
2025 } 2028 }
2026 } 2029 }
2027 2030
2028 // Read GData-related preferences. 2031 // Read GData-related preferences.
2029 bool GetGDataPreferencesFunction::RunImpl() { 2032 bool GetGDataPreferencesFunction::RunImpl() {
2030 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 2033 scoped_ptr<DictionaryValue> value(new DictionaryValue());
2031 2034
2032 const PrefService* service = profile_->GetPrefs(); 2035 const PrefService* service = profile_->GetPrefs();
2033 2036
2037 bool driveEnabled = gdata::util::IsGDataAvailable(profile_);
2038
2039 if (driveEnabled)
2040 AddGDataMountPoint(profile_, extension_id(), render_view_host());
2041
2042 value->SetBoolean("driveEnabled", driveEnabled);
2043
2034 value->SetBoolean("cellularDisabled", 2044 value->SetBoolean("cellularDisabled",
2035 service->GetBoolean(prefs::kDisableGDataOverCellular)); 2045 service->GetBoolean(prefs::kDisableGDataOverCellular));
2036 2046
2037 value->SetBoolean("hostedFilesDisabled", 2047 value->SetBoolean("hostedFilesDisabled",
2038 service->GetBoolean(prefs::kDisableGDataHostedFiles)); 2048 service->GetBoolean(prefs::kDisableGDataHostedFiles));
2039 2049
2040 result_.reset(value.release()); 2050 result_.reset(value.release());
2041 return true; 2051 return true;
2042 } 2052 }
2043 2053
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
2110 else if (active_network->type() == chromeos::TYPE_CELLULAR) 2120 else if (active_network->type() == chromeos::TYPE_CELLULAR)
2111 type_string = "cellular"; 2121 type_string = "cellular";
2112 else 2122 else
2113 type_string = "ethernet"; // Currently we do not care about other types. 2123 type_string = "ethernet"; // Currently we do not care about other types.
2114 2124
2115 value->SetString("type", type_string); 2125 value->SetString("type", type_string);
2116 result_.reset(value.release()); 2126 result_.reset(value.release());
2117 2127
2118 return true; 2128 return true;
2119 } 2129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698