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

Side by Side Diff: chrome/browser/chromeos/file_manager/fileapi_util.cc

Issue 147993003: Clarify and separate the concept of "Drive path" and "Filesystem relative path". (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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
« no previous file with comments | « chrome/browser/chromeos/file_manager/fileapi_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/file_manager/fileapi_util.h" 5 #include "chrome/browser/chromeos/file_manager/fileapi_util.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "chrome/browser/chromeos/drive/file_system_util.h"
8 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/extension_system.h" 10 #include "chrome/browser/extensions/extension_system.h"
10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
11 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/render_view_host.h" 13 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/site_instance.h" 14 #include "content/public/browser/site_instance.h"
14 #include "content/public/browser/storage_partition.h" 15 #include "content/public/browser/storage_partition.h"
15 #include "net/base/escape.h" 16 #include "net/base/escape.h"
16 #include "url/gurl.h" 17 #include "url/gurl.h"
17 #include "webkit/browser/fileapi/file_system_context.h" 18 #include "webkit/browser/fileapi/file_system_context.h"
18 #include "webkit/common/fileapi/file_system_util.h" 19 #include "webkit/common/fileapi/file_system_util.h"
19 20
20 namespace file_manager { 21 namespace file_manager {
21 namespace util { 22 namespace util {
22 23
24 namespace {
25
26 GURL ConvertRelativeFilePathToFileSystemUrl(const base::FilePath& relative_path,
27 const std::string& extension_id) {
28 GURL base_url = fileapi::GetFileSystemRootURI(
29 extensions::Extension::GetBaseURLFromExtensionId(extension_id),
30 fileapi::kFileSystemTypeExternal);
31 return GURL(base_url.spec() +
32 net::EscapeUrlEncodedData(relative_path.AsUTF8Unsafe(),
33 false)); // Space to %20 instead of +.
34 }
35
36 } // namespace
37
23 fileapi::FileSystemContext* GetFileSystemContextForExtensionId( 38 fileapi::FileSystemContext* GetFileSystemContextForExtensionId(
24 Profile* profile, 39 Profile* profile,
25 const std::string& extension_id) { 40 const std::string& extension_id) {
26 GURL site = extensions::ExtensionSystem::Get(profile)-> 41 GURL site = extensions::ExtensionSystem::Get(profile)->
27 extension_service()->GetSiteForExtensionId(extension_id); 42 extension_service()->GetSiteForExtensionId(extension_id);
28 return content::BrowserContext::GetStoragePartitionForSite(profile, site)-> 43 return content::BrowserContext::GetStoragePartitionForSite(profile, site)->
29 GetFileSystemContext(); 44 GetFileSystemContext();
30 } 45 }
31 46
32 fileapi::FileSystemContext* GetFileSystemContextForRenderViewHost( 47 fileapi::FileSystemContext* GetFileSystemContextForRenderViewHost(
33 Profile* profile, 48 Profile* profile,
34 content::RenderViewHost* render_view_host) { 49 content::RenderViewHost* render_view_host) {
35 content::SiteInstance* site_instance = render_view_host->GetSiteInstance(); 50 content::SiteInstance* site_instance = render_view_host->GetSiteInstance();
36 return content::BrowserContext::GetStoragePartition(profile, site_instance)-> 51 return content::BrowserContext::GetStoragePartition(profile, site_instance)->
37 GetFileSystemContext(); 52 GetFileSystemContext();
38 } 53 }
39 54
40 GURL ConvertRelativeFilePathToFileSystemUrl(const base::FilePath& relative_path, 55 base::FilePath ConvertDrivePathToRelativeFileSystemPath(
41 const std::string& extension_id) { 56 Profile* profile,
42 GURL base_url = fileapi::GetFileSystemRootURI( 57 const base::FilePath& drive_path) {
43 extensions::Extension::GetBaseURLFromExtensionId(extension_id), 58 // "drive-xxx"
44 fileapi::kFileSystemTypeExternal); 59 base::FilePath path = drive::util::GetDriveMountPointPath(profile).BaseName();
45 return GURL(base_url.spec() + 60 // appended with (|drive_path| - "drive").
46 net::EscapeUrlEncodedData(relative_path.AsUTF8Unsafe(), 61 drive::util::GetDriveGrandRootPath().AppendRelativePath(drive_path, &path);
47 false)); // Space to %20 instead of +. 62 return path;
48 } 63 }
49 64
50 bool ConvertAbsoluteFilePathToFileSystemUrl( 65 GURL ConvertDrivePathToFileSystemUrl(Profile* profile,
51 Profile* profile, 66 const base::FilePath& drive_path,
52 const base::FilePath& absolute_path, 67 const std::string& extension_id) {
53 const std::string& extension_id, 68 const base::FilePath relative_path =
54 GURL* url) { 69 ConvertDrivePathToRelativeFileSystemPath(profile, drive_path);
70 return ConvertRelativeFilePathToFileSystemUrl(drive_path, extension_id);
71 }
72
73 bool ConvertAbsoluteFilePathToFileSystemUrl(Profile* profile,
74 const base::FilePath& absolute_path,
75 const std::string& extension_id,
76 GURL* url) {
55 base::FilePath relative_path; 77 base::FilePath relative_path;
56 if (!ConvertAbsoluteFilePathToRelativeFileSystemPath( 78 if (!ConvertAbsoluteFilePathToRelativeFileSystemPath(profile,
57 profile, 79 extension_id,
58 extension_id, 80 absolute_path,
59 absolute_path, 81 &relative_path)) {
60 &relative_path)) {
61 return false; 82 return false;
62 } 83 }
63 *url = ConvertRelativeFilePathToFileSystemUrl(relative_path, extension_id); 84 *url = ConvertRelativeFilePathToFileSystemUrl(relative_path, extension_id);
64 return true; 85 return true;
65 } 86 }
66 87
67 bool ConvertAbsoluteFilePathToRelativeFileSystemPath( 88 bool ConvertAbsoluteFilePathToRelativeFileSystemPath(
68 Profile* profile, 89 Profile* profile,
69 const std::string& extension_id, 90 const std::string& extension_id,
70 const base::FilePath& absolute_path, 91 const base::FilePath& absolute_path,
(...skipping 16 matching lines...) Expand all
87 108
88 // Find if this file path is managed by the external backend. 109 // Find if this file path is managed by the external backend.
89 if (!backend->GetVirtualPath(absolute_path, virtual_path)) 110 if (!backend->GetVirtualPath(absolute_path, virtual_path))
90 return false; 111 return false;
91 112
92 return true; 113 return true;
93 } 114 }
94 115
95 } // namespace util 116 } // namespace util
96 } // namespace file_manager 117 } // namespace file_manager
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/fileapi_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698