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/sync_file_system/local_file_sync_service.h" | 5 #include "chrome/browser/sync_file_system/local_file_sync_service.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/extensions/extension_system.h" | 9 #include "chrome/browser/extensions/extension_system.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/sync_file_system/local_change_processor.h" | 11 #include "chrome/browser/sync_file_system/local_change_processor.h" |
12 #include "chrome/browser/sync_file_system/logger.h" | 12 #include "chrome/browser/sync_file_system/logger.h" |
13 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/site_instance.h" | 15 #include "content/public/browser/site_instance.h" |
16 #include "content/public/browser/storage_partition.h" | 16 #include "content/public/browser/storage_partition.h" |
17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
18 #include "webkit/browser/fileapi/file_system_context.h" | 18 #include "webkit/browser/fileapi/file_system_context.h" |
19 #include "webkit/browser/fileapi/file_system_url.h" | 19 #include "webkit/browser/fileapi/file_system_url.h" |
20 #include "webkit/browser/fileapi/syncable/file_change.h" | 20 #include "webkit/browser/fileapi/syncable/file_change.h" |
21 #include "webkit/browser/fileapi/syncable/local_file_change_tracker.h" | 21 #include "webkit/browser/fileapi/syncable/local_file_change_tracker.h" |
22 #include "webkit/browser/fileapi/syncable/local_file_sync_context.h" | 22 #include "webkit/browser/fileapi/syncable/local_file_sync_context.h" |
23 #include "webkit/browser/fileapi/syncable/sync_file_metadata.h" | 23 #include "webkit/browser/fileapi/syncable/sync_file_metadata.h" |
| 24 #include "webkit/browser/fileapi/syncable/syncable_sandbox_mount_point_provider.
h" |
24 | 25 |
25 using content::BrowserThread; | 26 using content::BrowserThread; |
26 using fileapi::FileSystemURL; | 27 using fileapi::FileSystemURL; |
27 | 28 |
28 namespace sync_file_system { | 29 namespace sync_file_system { |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
32 void PrepareForProcessRemoteChangeCallbackAdapter( | 33 void PrepareForProcessRemoteChangeCallbackAdapter( |
33 const RemoteChangeProcessor::PrepareChangeCallback& callback, | 34 const RemoteChangeProcessor::PrepareChangeCallback& callback, |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 // This could happen if this is called for apps/origins that haven't | 277 // This could happen if this is called for apps/origins that haven't |
277 // been initialized yet, or for apps/origins that are disabled. | 278 // been initialized yet, or for apps/origins that are disabled. |
278 // (Local change tracker could call this for uninitialized origins | 279 // (Local change tracker could call this for uninitialized origins |
279 // while it's reading dirty files from the database in the | 280 // while it's reading dirty files from the database in the |
280 // initialization phase.) | 281 // initialization phase.) |
281 pending_origins_with_changes_.insert(origin); | 282 pending_origins_with_changes_.insert(origin); |
282 continue; | 283 continue; |
283 } | 284 } |
284 need_notification = true; | 285 need_notification = true; |
285 fileapi::FileSystemContext* context = origin_to_contexts_[origin]; | 286 fileapi::FileSystemContext* context = origin_to_contexts_[origin]; |
286 DCHECK(context->change_tracker()); | 287 SyncableSandboxMountPointProvider* provider = |
| 288 SyncableSandboxMountPointProvider::GetProvider(context); |
| 289 DCHECK(provider); |
| 290 DCHECK(provider->change_tracker()); |
287 origin_change_map_.SetOriginChangeCount( | 291 origin_change_map_.SetOriginChangeCount( |
288 origin, context->change_tracker()->num_changes()); | 292 origin, provider->change_tracker()->num_changes()); |
289 } | 293 } |
290 if (!need_notification) | 294 if (!need_notification) |
291 return; | 295 return; |
292 int64 num_changes = origin_change_map_.GetTotalChangeCount(); | 296 int64 num_changes = origin_change_map_.GetTotalChangeCount(); |
293 FOR_EACH_OBSERVER(Observer, change_observers_, | 297 FOR_EACH_OBSERVER(Observer, change_observers_, |
294 OnLocalChangeAvailable(num_changes)); | 298 OnLocalChangeAvailable(num_changes)); |
295 } | 299 } |
296 | 300 |
297 void LocalFileSyncService::SetOriginEnabled(const GURL& origin, bool enabled) { | 301 void LocalFileSyncService::SetOriginEnabled(const GURL& origin, bool enabled) { |
298 if (!ContainsKey(origin_to_contexts_, origin)) | 302 if (!ContainsKey(origin_to_contexts_, origin)) |
(...skipping 10 matching lines...) Expand all Loading... |
309 callback.Run(status); | 313 callback.Run(status); |
310 return; | 314 return; |
311 } | 315 } |
312 DCHECK(file_system_context); | 316 DCHECK(file_system_context); |
313 origin_to_contexts_[app_origin] = file_system_context; | 317 origin_to_contexts_[app_origin] = file_system_context; |
314 | 318 |
315 if (pending_origins_with_changes_.find(app_origin) != | 319 if (pending_origins_with_changes_.find(app_origin) != |
316 pending_origins_with_changes_.end()) { | 320 pending_origins_with_changes_.end()) { |
317 // We have remaining changes for the origin. | 321 // We have remaining changes for the origin. |
318 pending_origins_with_changes_.erase(app_origin); | 322 pending_origins_with_changes_.erase(app_origin); |
319 DCHECK(file_system_context->change_tracker()); | 323 SyncableSandboxMountPointProvider* provider = |
| 324 SyncableSandboxMountPointProvider::GetProvider(file_system_context); |
| 325 DCHECK(provider); |
| 326 DCHECK(provider->change_tracker()); |
320 origin_change_map_.SetOriginChangeCount( | 327 origin_change_map_.SetOriginChangeCount( |
321 app_origin, file_system_context->change_tracker()->num_changes()); | 328 app_origin, provider->change_tracker()->num_changes()); |
322 int64 num_changes = origin_change_map_.GetTotalChangeCount(); | 329 int64 num_changes = origin_change_map_.GetTotalChangeCount(); |
323 FOR_EACH_OBSERVER(Observer, change_observers_, | 330 FOR_EACH_OBSERVER(Observer, change_observers_, |
324 OnLocalChangeAvailable(num_changes)); | 331 OnLocalChangeAvailable(num_changes)); |
325 } | 332 } |
326 callback.Run(status); | 333 callback.Run(status); |
327 } | 334 } |
328 | 335 |
329 void LocalFileSyncService::DidInitializeForRemoteSync( | 336 void LocalFileSyncService::DidInitializeForRemoteSync( |
330 const FileSystemURL& url, | 337 const FileSystemURL& url, |
331 fileapi::FileSystemContext* file_system_context, | 338 fileapi::FileSystemContext* file_system_context, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 changes.front(), | 431 changes.front(), |
425 sync_file_info.local_file_path, | 432 sync_file_info.local_file_path, |
426 sync_file_info.metadata, | 433 sync_file_info.metadata, |
427 url, | 434 url, |
428 base::Bind(&LocalFileSyncService::ProcessNextChangeForURL, | 435 base::Bind(&LocalFileSyncService::ProcessNextChangeForURL, |
429 AsWeakPtr(), sync_file_info, | 436 AsWeakPtr(), sync_file_info, |
430 changes.front(), changes.PopAndGetNewList())); | 437 changes.front(), changes.PopAndGetNewList())); |
431 } | 438 } |
432 | 439 |
433 } // namespace sync_file_system | 440 } // namespace sync_file_system |
OLD | NEW |