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/gdata/gdata_util.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "chrome/browser/chromeos/login/user_manager.h" | 28 #include "chrome/browser/chromeos/login/user_manager.h" |
29 #include "chrome/browser/prefs/pref_service.h" | 29 #include "chrome/browser/prefs/pref_service.h" |
30 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
32 #include "chrome/browser/ui/browser_finder.h" | 32 #include "chrome/browser/ui/browser_finder.h" |
33 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
34 #include "content/public/browser/child_process_security_policy.h" | 34 #include "content/public/browser/child_process_security_policy.h" |
35 #include "net/base/escape.h" | 35 #include "net/base/escape.h" |
36 #include "third_party/libxml/chromium/libxml_utils.h" | 36 #include "third_party/libxml/chromium/libxml_utils.h" |
37 | 37 |
| 38 using content::BrowserThread; |
| 39 |
38 namespace gdata { | 40 namespace gdata { |
39 namespace util { | 41 namespace util { |
40 | 42 |
41 namespace { | 43 namespace { |
42 | 44 |
43 const char kGDataSpecialRootPath[] = "/special"; | 45 const char kGDataSpecialRootPath[] = "/special"; |
44 | 46 |
45 const char kGDataMountPointPath[] = "/special/drive"; | 47 const char kGDataMountPointPath[] = "/special/drive"; |
46 | 48 |
47 const FilePath::CharType* kGDataMountPointPathComponents[] = { | 49 const FilePath::CharType* kGDataMountPointPathComponents[] = { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 87 } |
86 std::string edit_url; | 88 std::string edit_url; |
87 if (!dict_val->GetString("url", &edit_url)) { | 89 if (!dict_val->GetString("url", &edit_url)) { |
88 NOTREACHED() << "url field doesn't exist in " << json; | 90 NOTREACHED() << "url field doesn't exist in " << json; |
89 return; | 91 return; |
90 } | 92 } |
91 *url = GURL(edit_url); | 93 *url = GURL(edit_url); |
92 DVLOG(1) << "edit url " << *url; | 94 DVLOG(1) << "edit url " << *url; |
93 } | 95 } |
94 | 96 |
95 void OpenEditURLUIThread(Profile* profile, GURL* edit_url) { | 97 void OpenEditURLUIThread(Profile* profile, const GURL* edit_url) { |
96 Browser* browser = browser::FindLastActiveWithProfile(profile); | 98 Browser* browser = browser::FindLastActiveWithProfile(profile); |
97 if (browser) { | 99 if (browser) { |
98 browser->OpenURL(content::OpenURLParams(*edit_url, content::Referrer(), | 100 browser->OpenURL(content::OpenURLParams(*edit_url, content::Referrer(), |
99 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); | 101 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); |
100 } | 102 } |
101 } | 103 } |
102 | 104 |
| 105 // Invoked upon completion of FindEntryByResourceId initiated by |
| 106 // ModifyGDataFileResourceUrl. |
| 107 void OnFindEntryByResourceId(Profile* profile, |
| 108 const std::string& resource_id, |
| 109 base::PlatformFileError error, |
| 110 GDataEntry* entry) { |
| 111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 112 |
| 113 if (error != base::PLATFORM_FILE_OK || !entry || !entry->AsGDataFile()) |
| 114 return; |
| 115 |
| 116 const std::string& file_name = entry->AsGDataFile()->file_name(); |
| 117 const GURL edit_url = GetFileResourceUrl(resource_id, file_name); |
| 118 OpenEditURLUIThread(profile, &edit_url); |
| 119 DVLOG(1) << "OnFindEntryByResourceId " << edit_url; |
| 120 } |
| 121 |
103 // Invoked upon completion of GetFileInfoByPathAsync initiated by | 122 // Invoked upon completion of GetFileInfoByPathAsync initiated by |
104 // InsertGDataCachePathPermissions. | 123 // InsertGDataCachePathPermissions. |
105 void OnGetFileInfoForInsertGDataCachePathsPermissions( | 124 void OnGetFileInfoForInsertGDataCachePathsPermissions( |
106 Profile* profile, | 125 Profile* profile, |
107 std::vector<std::pair<FilePath, int> >* cache_paths, | 126 std::vector<std::pair<FilePath, int> >* cache_paths, |
108 const base::Closure& callback, | 127 const base::Closure& callback, |
109 base::PlatformFileError error, | 128 base::PlatformFileError error, |
110 scoped_ptr<GDataFileProto> file_info) { | 129 scoped_ptr<GDataFileProto> file_info) { |
111 DCHECK(profile); | 130 DCHECK(profile); |
112 DCHECK(cache_paths); | 131 DCHECK(cache_paths); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 std::string url(base::StringPrintf( | 196 std::string url(base::StringPrintf( |
178 "%s:%s", | 197 "%s:%s", |
179 chrome::kDriveScheme, | 198 chrome::kDriveScheme, |
180 net::EscapePath(resource_id).c_str())); | 199 net::EscapePath(resource_id).c_str())); |
181 return GURL(url); | 200 return GURL(url); |
182 } | 201 } |
183 | 202 |
184 void ModifyGDataFileResourceUrl(Profile* profile, | 203 void ModifyGDataFileResourceUrl(Profile* profile, |
185 const FilePath& gdata_cache_path, | 204 const FilePath& gdata_cache_path, |
186 GURL* url) { | 205 GURL* url) { |
| 206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 207 |
187 GDataFileSystem* file_system = GetGDataFileSystem(profile); | 208 GDataFileSystem* file_system = GetGDataFileSystem(profile); |
188 if (!file_system) | 209 if (!file_system) |
189 return; | 210 return; |
190 GDataCache* cache = GetGDataCache(profile); | 211 GDataCache* cache = GetGDataCache(profile); |
191 if (!cache) | 212 if (!cache) |
192 return; | 213 return; |
193 | 214 |
194 // Handle hosted documents. The edit url is in the temporary file, so we | |
195 // read it on a blocking thread. | |
196 if (cache->GetCacheDirectoryPath( | 215 if (cache->GetCacheDirectoryPath( |
197 GDataCache::CACHE_TYPE_TMP_DOCUMENTS).IsParent( | 216 GDataCache::CACHE_TYPE_TMP_DOCUMENTS).IsParent( |
198 gdata_cache_path)) { | 217 gdata_cache_path)) { |
| 218 // Handle hosted documents. The edit url is in the temporary file, so we |
| 219 // read it on a blocking thread. |
199 GURL* edit_url = new GURL(); | 220 GURL* edit_url = new GURL(); |
200 content::BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, | 221 content::BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, |
201 base::Bind(&GetHostedDocumentURLBlockingThread, | 222 base::Bind(&GetHostedDocumentURLBlockingThread, |
202 gdata_cache_path, edit_url), | 223 gdata_cache_path, edit_url), |
203 base::Bind(&OpenEditURLUIThread, profile, base::Owned(edit_url))); | 224 base::Bind(&OpenEditURLUIThread, profile, base::Owned(edit_url))); |
204 *url = GURL(); | 225 *url = GURL(); |
205 return; | 226 } else if (cache->GetCacheDirectoryPath( |
206 } | 227 GDataCache::CACHE_TYPE_TMP).IsParent(gdata_cache_path)) { |
207 | 228 // Handle all other gdata files. |
208 // Handle all other gdata files. | |
209 if (cache->GetCacheDirectoryPath( | |
210 GDataCache::CACHE_TYPE_TMP).IsParent(gdata_cache_path)) { | |
211 const std::string resource_id = | 229 const std::string resource_id = |
212 gdata_cache_path.BaseName().RemoveExtension().AsUTF8Unsafe(); | 230 gdata_cache_path.BaseName().RemoveExtension().AsUTF8Unsafe(); |
213 GDataEntry* entry = NULL; | 231 file_system->FindEntryByResourceId(resource_id, |
214 file_system->FindEntryByResourceIdSync( | 232 base::Bind(&OnFindEntryByResourceId, |
215 resource_id, base::Bind(&ReadOnlyFindEntryCallback, &entry)); | 233 profile, |
216 | 234 resource_id)); |
217 std::string file_name; | 235 *url = GURL(); |
218 if (entry && entry->AsGDataFile()) | |
219 file_name = entry->AsGDataFile()->file_name(); | |
220 | |
221 *url = gdata::util::GetFileResourceUrl(resource_id, file_name); | |
222 DVLOG(1) << "ModifyGDataFileResourceUrl " << *url; | |
223 } | 236 } |
224 } | 237 } |
225 | 238 |
226 bool IsUnderGDataMountPoint(const FilePath& path) { | 239 bool IsUnderGDataMountPoint(const FilePath& path) { |
227 return GetGDataMountPointPath() == path || | 240 return GetGDataMountPointPath() == path || |
228 GetGDataMountPointPath().IsParent(path); | 241 GetGDataMountPointPath().IsParent(path); |
229 } | 242 } |
230 | 243 |
231 GDataSearchPathType GetSearchPathStatus(const FilePath& path) { | 244 GDataSearchPathType GetSearchPathStatus(const FilePath& path) { |
232 std::vector<std::string> components; | 245 std::vector<std::string> components; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 // Assign the extracted extensions to md5 and extra_extension. | 419 // Assign the extracted extensions to md5 and extra_extension. |
407 int extension_count = extensions.size(); | 420 int extension_count = extensions.size(); |
408 *md5 = (extension_count > 0) ? extensions[extension_count - 1] : | 421 *md5 = (extension_count > 0) ? extensions[extension_count - 1] : |
409 std::string(); | 422 std::string(); |
410 *extra_extension = (extension_count > 1) ? extensions[extension_count - 2] : | 423 *extra_extension = (extension_count > 1) ? extensions[extension_count - 2] : |
411 std::string(); | 424 std::string(); |
412 } | 425 } |
413 | 426 |
414 } // namespace util | 427 } // namespace util |
415 } // namespace gdata | 428 } // namespace gdata |
OLD | NEW |