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

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

Issue 10546093: gdata: Move ownership of GDataCache to GDataSystemService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add TODO 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" 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 base::PLATFORM_FILE_READ | 56 base::PLATFORM_FILE_READ |
57 base::PLATFORM_FILE_EXCLUSIVE_READ | 57 base::PLATFORM_FILE_EXCLUSIVE_READ |
58 base::PLATFORM_FILE_ASYNC; 58 base::PLATFORM_FILE_ASYNC;
59 59
60 GDataFileSystem* GetGDataFileSystem(Profile* profile) { 60 GDataFileSystem* GetGDataFileSystem(Profile* profile) {
61 GDataSystemService* system_service = 61 GDataSystemService* system_service =
62 GDataSystemServiceFactory::GetForProfile(profile); 62 GDataSystemServiceFactory::GetForProfile(profile);
63 return system_service ? system_service->file_system() : NULL; 63 return system_service ? system_service->file_system() : NULL;
64 } 64 }
65 65
66 GDataCache* GetGDataCache(Profile* profile) {
67 GDataSystemService* system_service =
68 GDataSystemServiceFactory::GetForProfile(profile);
69 return system_service ? system_service->cache() : NULL;
70 }
71
66 void GetHostedDocumentURLBlockingThread(const FilePath& gdata_cache_path, 72 void GetHostedDocumentURLBlockingThread(const FilePath& gdata_cache_path,
67 GURL* url) { 73 GURL* url) {
68 std::string json; 74 std::string json;
69 if (!file_util::ReadFileToString(gdata_cache_path, &json)) { 75 if (!file_util::ReadFileToString(gdata_cache_path, &json)) {
70 NOTREACHED() << "Unable to read file " << gdata_cache_path.value(); 76 NOTREACHED() << "Unable to read file " << gdata_cache_path.value();
71 return; 77 return;
72 } 78 }
73 DVLOG(1) << "Hosted doc content " << json; 79 DVLOG(1) << "Hosted doc content " << json;
74 scoped_ptr<base::Value> val(base::JSONReader::Read(json)); 80 scoped_ptr<base::Value> val(base::JSONReader::Read(json));
75 base::DictionaryValue* dict_val; 81 base::DictionaryValue* dict_val;
(...skipping 23 matching lines...) Expand all
99 void OnGetFileInfoForInsertGDataCachePathsPermissions( 105 void OnGetFileInfoForInsertGDataCachePathsPermissions(
100 Profile* profile, 106 Profile* profile,
101 std::vector<std::pair<FilePath, int> >* cache_paths, 107 std::vector<std::pair<FilePath, int> >* cache_paths,
102 const base::Closure& callback, 108 const base::Closure& callback,
103 base::PlatformFileError error, 109 base::PlatformFileError error,
104 scoped_ptr<GDataFileProto> file_info) { 110 scoped_ptr<GDataFileProto> file_info) {
105 DCHECK(profile); 111 DCHECK(profile);
106 DCHECK(cache_paths); 112 DCHECK(cache_paths);
107 DCHECK(!callback.is_null()); 113 DCHECK(!callback.is_null());
108 114
109 GDataFileSystem* file_system = GetGDataFileSystem(profile); 115 GDataCache* cache = GetGDataCache(profile);
110 if (!file_system || error != base::PLATFORM_FILE_OK) { 116 if (!cache || error != base::PLATFORM_FILE_OK) {
111 callback.Run(); 117 callback.Run();
112 return; 118 return;
113 } 119 }
114 120
115 DCHECK(file_info.get()); 121 DCHECK(file_info.get());
116 std::string resource_id = file_info->gdata_entry().resource_id(); 122 std::string resource_id = file_info->gdata_entry().resource_id();
117 std::string file_md5 = file_info->file_md5(); 123 std::string file_md5 = file_info->file_md5();
118 124
119 // We check permissions for raw cache file paths only for read-only 125 // We check permissions for raw cache file paths only for read-only
120 // operations (when fileEntry.file() is called), so read only permissions 126 // operations (when fileEntry.file() is called), so read only permissions
121 // should be sufficient for all cache paths. For the rest of supported 127 // should be sufficient for all cache paths. For the rest of supported
122 // operations the file access check is done for drive/ paths. 128 // operations the file access check is done for drive/ paths.
123 cache_paths->push_back(std::make_pair( 129 cache_paths->push_back(std::make_pair(
124 file_system->GetCacheFilePath(resource_id, file_md5, 130 cache->GetCacheFilePath(resource_id, file_md5,
125 GDataCache::CACHE_TYPE_PERSISTENT, 131 GDataCache::CACHE_TYPE_PERSISTENT,
126 GDataCache::CACHED_FILE_FROM_SERVER), 132 GDataCache::CACHED_FILE_FROM_SERVER),
127 kReadOnlyFilePermissions)); 133 kReadOnlyFilePermissions));
128 // TODO(tbarzic): When we start supporting openFile operation, we may have to 134 // TODO(tbarzic): When we start supporting openFile operation, we may have to
129 // change permission for localy modified files to match handler's permissions. 135 // change permission for localy modified files to match handler's permissions.
130 cache_paths->push_back(std::make_pair( 136 cache_paths->push_back(std::make_pair(
131 file_system->GetCacheFilePath(resource_id, file_md5, 137 cache->GetCacheFilePath(resource_id, file_md5,
132 GDataCache::CACHE_TYPE_PERSISTENT, 138 GDataCache::CACHE_TYPE_PERSISTENT,
133 GDataCache::CACHED_FILE_LOCALLY_MODIFIED), 139 GDataCache::CACHED_FILE_LOCALLY_MODIFIED),
134 kReadOnlyFilePermissions)); 140 kReadOnlyFilePermissions));
135 cache_paths->push_back(std::make_pair( 141 cache_paths->push_back(std::make_pair(
136 file_system->GetCacheFilePath(resource_id, file_md5, 142 cache->GetCacheFilePath(resource_id, file_md5,
137 GDataCache::CACHE_TYPE_PERSISTENT, 143 GDataCache::CACHE_TYPE_PERSISTENT,
138 GDataCache::CACHED_FILE_MOUNTED), 144 GDataCache::CACHED_FILE_MOUNTED),
139 kReadOnlyFilePermissions)); 145 kReadOnlyFilePermissions));
140 cache_paths->push_back(std::make_pair( 146 cache_paths->push_back(std::make_pair(
141 file_system->GetCacheFilePath(resource_id, file_md5, 147 cache->GetCacheFilePath(resource_id, file_md5,
142 GDataCache::CACHE_TYPE_TMP, 148 GDataCache::CACHE_TYPE_TMP,
143 GDataCache::CACHED_FILE_FROM_SERVER), 149 GDataCache::CACHED_FILE_FROM_SERVER),
144 kReadOnlyFilePermissions)); 150 kReadOnlyFilePermissions));
145 151
146 callback.Run(); 152 callback.Run();
147 } 153 }
148 154
149 } // namespace 155 } // namespace
150 156
151 const FilePath& GetGDataMountPointPath() { 157 const FilePath& GetGDataMountPointPath() {
(...skipping 22 matching lines...) Expand all
174 net::EscapePath(resource_id).c_str())); 180 net::EscapePath(resource_id).c_str()));
175 return GURL(url); 181 return GURL(url);
176 } 182 }
177 183
178 void ModifyGDataFileResourceUrl(Profile* profile, 184 void ModifyGDataFileResourceUrl(Profile* profile,
179 const FilePath& gdata_cache_path, 185 const FilePath& gdata_cache_path,
180 GURL* url) { 186 GURL* url) {
181 GDataFileSystem* file_system = GetGDataFileSystem(profile); 187 GDataFileSystem* file_system = GetGDataFileSystem(profile);
182 if (!file_system) 188 if (!file_system)
183 return; 189 return;
190 GDataCache* cache = GetGDataCache(profile);
191 if (!cache)
192 return;
184 193
185 // Handle hosted documents. The edit url is in the temporary file, so we 194 // Handle hosted documents. The edit url is in the temporary file, so we
186 // read it on a blocking thread. 195 // read it on a blocking thread.
187 if (file_system->GetCacheDirectoryPath( 196 if (cache->GetCacheDirectoryPath(
188 GDataCache::CACHE_TYPE_TMP_DOCUMENTS).IsParent( 197 GDataCache::CACHE_TYPE_TMP_DOCUMENTS).IsParent(
189 gdata_cache_path)) { 198 gdata_cache_path)) {
190 GURL* edit_url = new GURL(); 199 GURL* edit_url = new GURL();
191 content::BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, 200 content::BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE,
192 base::Bind(&GetHostedDocumentURLBlockingThread, 201 base::Bind(&GetHostedDocumentURLBlockingThread,
193 gdata_cache_path, edit_url), 202 gdata_cache_path, edit_url),
194 base::Bind(&OpenEditURLUIThread, profile, base::Owned(edit_url))); 203 base::Bind(&OpenEditURLUIThread, profile, base::Owned(edit_url)));
195 *url = GURL(); 204 *url = GURL();
196 return; 205 return;
197 } 206 }
198 207
199 // Handle all other gdata files. 208 // Handle all other gdata files.
200 if (file_system->GetCacheDirectoryPath( 209 if (cache->GetCacheDirectoryPath(
201 GDataCache::CACHE_TYPE_TMP).IsParent(gdata_cache_path)) { 210 GDataCache::CACHE_TYPE_TMP).IsParent(gdata_cache_path)) {
202 const std::string resource_id = 211 const std::string resource_id =
203 gdata_cache_path.BaseName().RemoveExtension().AsUTF8Unsafe(); 212 gdata_cache_path.BaseName().RemoveExtension().AsUTF8Unsafe();
204 GDataEntry* entry = NULL; 213 GDataEntry* entry = NULL;
205 file_system->FindEntryByResourceIdSync( 214 file_system->FindEntryByResourceIdSync(
206 resource_id, base::Bind(&ReadOnlyFindEntryCallback, &entry)); 215 resource_id, base::Bind(&ReadOnlyFindEntryCallback, &entry));
207 216
208 std::string file_name; 217 std::string file_name;
209 if (entry && entry->AsGDataFile()) 218 if (entry && entry->AsGDataFile())
210 file_name = entry->AsGDataFile()->file_name(); 219 file_name = entry->AsGDataFile()->file_name();
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 // Assign the extracted extensions to md5 and extra_extension. 406 // Assign the extracted extensions to md5 and extra_extension.
398 int extension_count = extensions.size(); 407 int extension_count = extensions.size();
399 *md5 = (extension_count > 0) ? extensions[extension_count - 1] : 408 *md5 = (extension_count > 0) ? extensions[extension_count - 1] :
400 std::string(); 409 std::string();
401 *extra_extension = (extension_count > 1) ? extensions[extension_count - 2] : 410 *extra_extension = (extension_count > 1) ? extensions[extension_count - 2] :
402 std::string(); 411 std::string();
403 } 412 }
404 413
405 } // namespace util 414 } // namespace util
406 } // namespace gdata 415 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_system_service.cc ('k') | chrome/browser/chromeos/gdata/mock_gdata_file_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698