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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_util.cc

Issue 10543037: gdata: Convert public synchronous functions in GDataFileSystem to asynchronous. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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/gdata/gdata_util.h"
6
7 #include <string> 5 #include <string>
8 #include <vector> 6 #include <vector>
9 #include <utility> 7 #include <utility>
10 8
11 #include "base/basictypes.h" 9 #include "base/basictypes.h"
12 #include "base/bind.h" 10 #include "base/bind.h"
13 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
14 #include "base/file_path.h" 12 #include "base/file_path.h"
15 #include "base/file_util.h" 13 #include "base/file_util.h"
16 #include "base/json/json_reader.h" 14 #include "base/json/json_reader.h"
17 #include "base/logging.h" 15 #include "base/logging.h"
18 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
19 #include "base/string_util.h" 17 #include "base/string_util.h"
20 #include "base/threading/sequenced_worker_pool.h" 18 #include "base/threading/sequenced_worker_pool.h"
21 #include "chrome/common/chrome_version_info.h" 19 #include "chrome/common/chrome_version_info.h"
22 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
23 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
22 #include "chrome/browser/chromeos/gdata/gdata.pb.h"
24 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" 23 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
25 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" 24 #include "chrome/browser/chromeos/gdata/gdata_system_service.h"
25 #include "chrome/browser/chromeos/gdata/gdata_util.h"
satorux1 2012/06/07 22:47:17 Please move this back to the original place. htt
tbarzic 2012/06/07 22:47:56 why did you move this here??
hshi1 2012/06/08 00:22:05 Done.
hshi1 2012/06/08 00:22:05 Done. I originally moved the line to avoid a compi
26 #include "chrome/browser/chromeos/login/user.h" 26 #include "chrome/browser/chromeos/login/user.h"
27 #include "chrome/browser/chromeos/login/user_manager.h" 27 #include "chrome/browser/chromeos/login/user_manager.h"
28 #include "chrome/browser/prefs/pref_service.h" 28 #include "chrome/browser/prefs/pref_service.h"
29 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/ui/browser.h" 30 #include "chrome/browser/ui/browser.h"
31 #include "chrome/browser/ui/browser_finder.h" 31 #include "chrome/browser/ui/browser_finder.h"
32 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
33 #include "content/public/browser/child_process_security_policy.h" 33 #include "content/public/browser/child_process_security_policy.h"
34 #include "net/base/escape.h" 34 #include "net/base/escape.h"
35 #include "third_party/libxml/chromium/libxml_utils.h" 35 #include "third_party/libxml/chromium/libxml_utils.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 222
223 // -1 to include 'drive'. 223 // -1 to include 'drive'.
224 FilePath extracted; 224 FilePath extracted;
225 for (size_t i = arraysize(kGDataMountPointPathComponents) - 1; 225 for (size_t i = arraysize(kGDataMountPointPathComponents) - 1;
226 i < components.size(); ++i) { 226 i < components.size(); ++i) {
227 extracted = extracted.Append(components[i]); 227 extracted = extracted.Append(components[i]);
228 } 228 }
229 return extracted; 229 return extracted;
230 } 230 }
231 231
232 void InsertGDataCachePathsPermissions( 232 void OnGetFileInfoForInsertGDataCachePathsPermissions(
satorux1 2012/06/07 22:47:17 Please move this to anonymous namespace. Please wr
hshi1 2012/06/08 00:22:05 Done.
233 Profile* profile, 233 GDataFileSystem* file_system,
tbarzic 2012/06/07 22:47:56 I'm not sure how safe is passing file_system point
hshi1 2012/06/08 00:22:05 I'm going to change this to obtain file_system poi
234 const FilePath& gdata_path, 234 std::vector<std::pair<FilePath, int> >* cache_paths,
235 std::vector<std::pair<FilePath, int> >* cache_paths ) { 235 const base::Closure& callback,
236 DCHECK(cache_paths); 236 base::PlatformFileError error,
237 scoped_ptr<GDataFileProto> file_info) {
238 std::string resource_id;
239 std::string file_md5;
237 240
238 GDataFileSystem* file_system = GetGDataFileSystem(profile); 241 // TODO(hshi): GetFileInfoByPathAsync may fail when the gdata file is not
tbarzic 2012/06/07 22:47:56 Are you sure? AFAIK GetFileInfoByPath doesn't chec
239 if (!file_system) 242 // present in cache. For now just grant permission to the entire cache subdir.
tbarzic 2012/06/07 22:47:56 why don't we just ignore the file in that case (or
hshi1 2012/06/08 00:22:05 There may be bugs elsewhere but my observation at
240 return; 243 if (error == base::PLATFORM_FILE_OK && file_info.get()) {
241 244 resource_id = file_info->gdata_entry().resource_id();
242 GDataFileProperties file_properties; 245 file_md5 = file_info->file_md5();
243 file_system->GetFileInfoByPath(gdata_path, &file_properties); 246 }
244
245 std::string resource_id = file_properties.resource_id;
246 std::string file_md5 = file_properties.file_md5;
247 247
248 // We check permissions for raw cache file paths only for read-only 248 // We check permissions for raw cache file paths only for read-only
249 // operations (when fileEntry.file() is called), so read only permissions 249 // operations (when fileEntry.file() is called), so read only permissions
250 // should be sufficient for all cache paths. For the rest of supported 250 // should be sufficient for all cache paths. For the rest of supported
251 // operations the file access check is done for drive/ paths. 251 // operations the file access check is done for drive/ paths.
252 cache_paths->push_back(std::make_pair( 252 cache_paths->push_back(std::make_pair(
253 file_system->GetCacheFilePath(resource_id, file_md5, 253 file_system->GetCacheFilePath(resource_id, file_md5,
254 GDataCache::CACHE_TYPE_PERSISTENT, 254 GDataCache::CACHE_TYPE_PERSISTENT,
255 GDataFileSystem::CACHED_FILE_FROM_SERVER), 255 GDataFileSystem::CACHED_FILE_FROM_SERVER),
256 kReadOnlyFilePermissions)); 256 kReadOnlyFilePermissions));
257 // TODO(tbarzic): When we start supporting openFile operation, we may have to 257 // TODO(tbarzic): When we start supporting openFile operation, we may have to
258 // change permission for localy modified files to match handler's permissions. 258 // change permission for localy modified files to match handler's permissions.
259 cache_paths->push_back(std::make_pair( 259 cache_paths->push_back(std::make_pair(
260 file_system->GetCacheFilePath(resource_id, file_md5, 260 file_system->GetCacheFilePath(resource_id, file_md5,
261 GDataCache::CACHE_TYPE_PERSISTENT, 261 GDataCache::CACHE_TYPE_PERSISTENT,
262 GDataFileSystem::CACHED_FILE_LOCALLY_MODIFIED), 262 GDataFileSystem::CACHED_FILE_LOCALLY_MODIFIED),
263 kReadOnlyFilePermissions)); 263 kReadOnlyFilePermissions));
264 cache_paths->push_back(std::make_pair( 264 cache_paths->push_back(std::make_pair(
265 file_system->GetCacheFilePath(resource_id, file_md5, 265 file_system->GetCacheFilePath(resource_id, file_md5,
266 GDataCache::CACHE_TYPE_PERSISTENT, 266 GDataCache::CACHE_TYPE_PERSISTENT,
267 GDataFileSystem::CACHED_FILE_MOUNTED), 267 GDataFileSystem::CACHED_FILE_MOUNTED),
268 kReadOnlyFilePermissions)); 268 kReadOnlyFilePermissions));
269 cache_paths->push_back(std::make_pair( 269 cache_paths->push_back(std::make_pair(
270 file_system->GetCacheFilePath(resource_id, file_md5, 270 file_system->GetCacheFilePath(resource_id, file_md5,
271 GDataCache::CACHE_TYPE_TMP, 271 GDataCache::CACHE_TYPE_TMP,
272 GDataFileSystem::CACHED_FILE_FROM_SERVER), 272 GDataFileSystem::CACHED_FILE_FROM_SERVER),
273 kReadOnlyFilePermissions)); 273 kReadOnlyFilePermissions));
274
275 callback.Run();
276 }
277
278 void InsertGDataCachePathsPermissions(
279 Profile* profile,
280 scoped_ptr<std::vector<FilePath> > gdata_paths,
281 std::vector<std::pair<FilePath, int> >* cache_paths,
282 const base::Closure& callback) {
283 DCHECK(profile);
284 DCHECK(gdata_paths.get());
285 DCHECK(cache_paths);
286
287 GDataFileSystem* file_system = GetGDataFileSystem(profile);
288 if (!file_system || gdata_paths->empty()) {
289 if (!callback.is_null())
290 callback.Run();
291 return;
292 }
293
294 FilePath gdata_path = gdata_paths->back();
295 gdata_paths->pop_back();
296
tbarzic 2012/06/07 22:47:56 Can you add a comment for this? It is not obvious
hshi1 2012/06/08 00:22:05 Done.
297 file_system->GetFileInfoByPathAsync(
satorux1 2012/06/07 22:47:17 You are creating a loop using the callback, which
hshi1 2012/06/08 00:22:05 Done.
298 gdata_path,
299 base::Bind(&OnGetFileInfoForInsertGDataCachePathsPermissions,
300 file_system,
301 cache_paths,
302 base::Bind(&InsertGDataCachePathsPermissions,
303 profile,
304 base::Passed(&gdata_paths),
305 cache_paths,
306 callback)));
274 } 307 }
275 308
276 bool IsGDataAvailable(Profile* profile) { 309 bool IsGDataAvailable(Profile* profile) {
277 if (!chromeos::UserManager::Get()->IsUserLoggedIn() || 310 if (!chromeos::UserManager::Get()->IsUserLoggedIn() ||
278 chromeos::UserManager::Get()->IsLoggedInAsGuest() || 311 chromeos::UserManager::Get()->IsLoggedInAsGuest() ||
279 chromeos::UserManager::Get()->IsLoggedInAsDemoUser()) 312 chromeos::UserManager::Get()->IsLoggedInAsDemoUser())
280 return false; 313 return false;
281 314
282 // Do not allow GData for incognito windows / guest mode. 315 // Do not allow GData for incognito windows / guest mode.
283 if (profile->IsOffTheRecord()) 316 if (profile->IsOffTheRecord())
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 // Assign the extracted extensions to md5 and extra_extension. 383 // Assign the extracted extensions to md5 and extra_extension.
351 int extension_count = extensions.size(); 384 int extension_count = extensions.size();
352 *md5 = (extension_count > 0) ? extensions[extension_count - 1] : 385 *md5 = (extension_count > 0) ? extensions[extension_count - 1] :
353 std::string(); 386 std::string();
354 *extra_extension = (extension_count > 1) ? extensions[extension_count - 2] : 387 *extra_extension = (extension_count > 1) ? extensions[extension_count - 2] :
355 std::string(); 388 std::string();
356 } 389 }
357 390
358 } // namespace util 391 } // namespace util
359 } // namespace gdata 392 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698