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/chromeos/drive/drive_file_system_util.h" | 5 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 browser->OpenURL(content::OpenURLParams(edit_url, content::Referrer(), | 108 browser->OpenURL(content::OpenURLParams(edit_url, content::Referrer(), |
109 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); | 109 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 // Invoked upon completion of GetEntryInfoByResourceId initiated by | 113 // Invoked upon completion of GetEntryInfoByResourceId initiated by |
114 // ModifyDriveFileResourceUrl. | 114 // ModifyDriveFileResourceUrl. |
115 void OnGetEntryInfoByResourceId(Profile* profile, | 115 void OnGetEntryInfoByResourceId(Profile* profile, |
116 const std::string& resource_id, | 116 const std::string& resource_id, |
117 DriveFileError error, | 117 DriveFileError error, |
118 const base::FilePath& /* drive_file_path */, | 118 const base::FilePath& drive_file_path, |
119 scoped_ptr<DriveEntryProto> entry_proto) { | 119 scoped_ptr<DriveEntryProto> entry_proto) { |
120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
121 | 121 |
122 if (error != DRIVE_FILE_OK) | 122 if (error != DRIVE_FILE_OK) |
123 return; | 123 return; |
124 | 124 |
125 DCHECK(entry_proto.get()); | 125 const GURL edit_url = FilePathToDriveURL(drive_file_path); |
126 const std::string& base_name = entry_proto->base_name(); | |
127 const GURL edit_url = GetFileResourceUrl(resource_id, base_name); | |
128 OpenEditURLUIThread(profile, edit_url); | 126 OpenEditURLUIThread(profile, edit_url); |
129 DVLOG(1) << "OnFindEntryByResourceId " << edit_url; | 127 DVLOG(1) << "OnGetEntryInfoByResourceId " << edit_url; |
130 } | 128 } |
131 | 129 |
132 } // namespace | 130 } // namespace |
133 | 131 |
134 | 132 |
135 const base::FilePath& GetDriveGrandRootPath() { | 133 const base::FilePath& GetDriveGrandRootPath() { |
136 CR_DEFINE_STATIC_LOCAL(base::FilePath, grand_root_path, | 134 CR_DEFINE_STATIC_LOCAL(base::FilePath, grand_root_path, |
137 (base::FilePath::FromUTF8Unsafe(util::kDriveGrandRootDirName))); | 135 (base::FilePath::FromUTF8Unsafe(util::kDriveGrandRootDirName))); |
138 return grand_root_path; | 136 return grand_root_path; |
139 } | 137 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 (base::FilePath::FromUTF8Unsafe(kDriveSpecialRootPath))); | 170 (base::FilePath::FromUTF8Unsafe(kDriveSpecialRootPath))); |
173 return drive_mount_path; | 171 return drive_mount_path; |
174 } | 172 } |
175 | 173 |
176 const base::FilePath& GetDriveMyDriveMountPointPath() { | 174 const base::FilePath& GetDriveMyDriveMountPointPath() { |
177 CR_DEFINE_STATIC_LOCAL(base::FilePath, drive_mydrive_mount_path, | 175 CR_DEFINE_STATIC_LOCAL(base::FilePath, drive_mydrive_mount_path, |
178 (base::FilePath::FromUTF8Unsafe(kDriveMyDriveMountPointPath))); | 176 (base::FilePath::FromUTF8Unsafe(kDriveMyDriveMountPointPath))); |
179 return drive_mydrive_mount_path; | 177 return drive_mydrive_mount_path; |
180 } | 178 } |
181 | 179 |
182 GURL GetFileResourceUrl(const std::string& resource_id, | 180 GURL FilePathToDriveURL(const base::FilePath& path) { |
183 const std::string& file_name) { | 181 std::string url(base::StringPrintf("%s:%s", |
184 std::string url(base::StringPrintf( | 182 chrome::kDriveScheme, |
185 "%s:%s", | 183 path.AsUTF8Unsafe().c_str())); |
186 chrome::kDriveScheme, | |
187 net::EscapePath(resource_id).c_str())); | |
188 return GURL(url); | 184 return GURL(url); |
189 } | 185 } |
190 | 186 |
| 187 base::FilePath DriveURLToFilePath(const GURL& url) { |
| 188 if (!url.is_valid() || url.scheme() != chrome::kDriveScheme) |
| 189 return base::FilePath(); |
| 190 std::string path_string = net::UnescapeURLComponent( |
| 191 url.path(), net::UnescapeRule::NORMAL); |
| 192 return base::FilePath::FromUTF8Unsafe(path_string); |
| 193 } |
| 194 |
191 void ModifyDriveFileResourceUrl(Profile* profile, | 195 void ModifyDriveFileResourceUrl(Profile* profile, |
192 const base::FilePath& drive_cache_path, | 196 const base::FilePath& drive_cache_path, |
193 GURL* url) { | 197 GURL* url) { |
194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
195 | 199 |
196 DriveFileSystemInterface* file_system = GetDriveFileSystem(profile); | 200 DriveFileSystemInterface* file_system = GetDriveFileSystem(profile); |
197 if (!file_system) | 201 if (!file_system) |
198 return; | 202 return; |
199 DriveCache* cache = GetDriveCache(profile); | 203 DriveCache* cache = GetDriveCache(profile); |
200 if (!cache) | 204 if (!cache) |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 proto->set_last_modified(file_info.last_modified.ToInternalValue()); | 434 proto->set_last_modified(file_info.last_modified.ToInternalValue()); |
431 proto->set_last_accessed(file_info.last_accessed.ToInternalValue()); | 435 proto->set_last_accessed(file_info.last_accessed.ToInternalValue()); |
432 proto->set_creation_time(file_info.creation_time.ToInternalValue()); | 436 proto->set_creation_time(file_info.creation_time.ToInternalValue()); |
433 } | 437 } |
434 | 438 |
435 void EmptyFileOperationCallback(DriveFileError error) { | 439 void EmptyFileOperationCallback(DriveFileError error) { |
436 } | 440 } |
437 | 441 |
438 } // namespace util | 442 } // namespace util |
439 } // namespace drive | 443 } // namespace drive |
OLD | NEW |