Chromium Code Reviews| 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 "components/browser_sync/profile_sync_service.h" | 5 #include "components/browser_sync/profile_sync_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <cstddef> | 9 #include <cstddef> |
| 10 #include <map> | 10 #include <map> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/feature_list.h" | 16 #include "base/feature_list.h" |
| 17 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/memory/memory_coordinator_client_registry.h" | |
| 19 #include "base/memory/ptr_util.h" | 20 #include "base/memory/ptr_util.h" |
| 20 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
| 21 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
| 22 #include "base/profiler/scoped_tracker.h" | 23 #include "base/profiler/scoped_tracker.h" |
| 23 #include "base/single_thread_task_runner.h" | 24 #include "base/single_thread_task_runner.h" |
| 24 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 25 #include "base/threading/thread_restrictions.h" | 26 #include "base/threading/thread_restrictions.h" |
| 26 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
| 27 #include "components/autofill/core/common/autofill_pref_names.h" | 28 #include "components/autofill/core/common/autofill_pref_names.h" |
| 28 #include "components/browser_sync/browser_sync_switches.h" | 29 #include "components/browser_sync/browser_sync_switches.h" |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 std::string last_version = sync_prefs_.GetLastRunVersion(); | 233 std::string last_version = sync_prefs_.GetLastRunVersion(); |
| 233 std::string current_version = PRODUCT_VERSION; | 234 std::string current_version = PRODUCT_VERSION; |
| 234 sync_prefs_.SetLastRunVersion(current_version); | 235 sync_prefs_.SetLastRunVersion(current_version); |
| 235 | 236 |
| 236 // Check for a major version change. Note that the versions have format | 237 // Check for a major version change. Note that the versions have format |
| 237 // MAJOR.MINOR.BUILD.PATCH. | 238 // MAJOR.MINOR.BUILD.PATCH. |
| 238 if (last_version.substr(0, last_version.find('.')) != | 239 if (last_version.substr(0, last_version.find('.')) != |
| 239 current_version.substr(0, current_version.find('.'))) { | 240 current_version.substr(0, current_version.find('.'))) { |
| 240 passphrase_prompt_triggered_by_version_ = true; | 241 passphrase_prompt_triggered_by_version_ = true; |
| 241 } | 242 } |
| 243 | |
| 244 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); | |
| 242 } | 245 } |
| 243 | 246 |
| 244 ProfileSyncService::~ProfileSyncService() { | 247 ProfileSyncService::~ProfileSyncService() { |
| 245 if (gaia_cookie_manager_service_) | 248 if (gaia_cookie_manager_service_) |
| 246 gaia_cookie_manager_service_->RemoveObserver(this); | 249 gaia_cookie_manager_service_->RemoveObserver(this); |
| 247 sync_prefs_.RemoveSyncPrefObserver(this); | 250 sync_prefs_.RemoveSyncPrefObserver(this); |
| 248 // Shutdown() should have been called before destruction. | 251 // Shutdown() should have been called before destruction. |
| 249 CHECK(!backend_initialized_); | 252 CHECK(!backend_initialized_); |
| 253 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this); | |
| 250 } | 254 } |
| 251 | 255 |
| 252 bool ProfileSyncService::CanSyncStart() const { | 256 bool ProfileSyncService::CanSyncStart() const { |
| 253 return IsSyncAllowed() && IsSyncRequested() && IsSignedIn(); | 257 return IsSyncAllowed() && IsSyncRequested() && IsSignedIn(); |
| 254 } | 258 } |
| 255 | 259 |
| 256 void ProfileSyncService::Initialize() { | 260 void ProfileSyncService::Initialize() { |
| 257 sync_client_->Initialize(); | 261 sync_client_->Initialize(); |
| 258 | 262 |
| 259 // We don't pass StartupController an Unretained reference to future-proof | 263 // We don't pass StartupController an Unretained reference to future-proof |
| (...skipping 2178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2438 if (!access_token_.empty() && !cache_guid.empty() && !birthday.empty()) { | 2442 if (!access_token_.empty() && !cache_guid.empty() && !birthday.empty()) { |
| 2439 sync_stopped_reporter_->ReportSyncStopped(access_token_, cache_guid, | 2443 sync_stopped_reporter_->ReportSyncStopped(access_token_, cache_guid, |
| 2440 birthday); | 2444 birthday); |
| 2441 } | 2445 } |
| 2442 } | 2446 } |
| 2443 | 2447 |
| 2444 void ProfileSyncService::OnMemoryPressure( | 2448 void ProfileSyncService::OnMemoryPressure( |
| 2445 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | 2449 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 2446 if (memory_pressure_level == | 2450 if (memory_pressure_level == |
| 2447 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | 2451 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
| 2448 sync_prefs_.SetMemoryPressureWarningCount( | 2452 IncrementMemoryPressureWarningCount(); |
| 2449 sync_prefs_.GetMemoryPressureWarningCount() + 1); | |
| 2450 } | 2453 } |
| 2451 } | 2454 } |
| 2452 | 2455 |
| 2456 void ProfileSyncService::OnMemoryStateChange(base::MemoryState state) { | |
| 2457 // TODO(hajimehoshi): Adjust the size of this memory usage according to | |
| 2458 // |state|. ProfileSyncService doesn't have a feature to limit memory usage at | |
| 2459 // present. | |
| 2460 switch (state) { | |
| 2461 case base::MemoryState::NORMAL: | |
| 2462 break; | |
| 2463 case base::MemoryState::THROTTLED: | |
| 2464 IncrementMemoryPressureWarningCount(); | |
| 2465 break; | |
| 2466 case base::MemoryState::SUSPENDED: | |
| 2467 // Note: Not supported at present. Fall through. | |
| 2468 case base::MemoryState::UNKNOWN: | |
| 2469 NOTREACHED(); | |
| 2470 break; | |
| 2471 } | |
| 2472 } | |
| 2473 | |
| 2474 void ProfileSyncService::IncrementMemoryPressureWarningCount() { | |
| 2475 sync_prefs_.SetMemoryPressureWarningCount( | |
| 2476 sync_prefs_.GetMemoryPressureWarningCount() + 1); | |
|
bashi
2016/10/03 23:26:53
Do we use the warning count to change behavior of
| |
| 2477 } | |
| 2478 | |
| 2453 void ProfileSyncService::ReportPreviousSessionMemoryWarningCount() { | 2479 void ProfileSyncService::ReportPreviousSessionMemoryWarningCount() { |
| 2454 int warning_received = sync_prefs_.GetMemoryPressureWarningCount(); | 2480 int warning_received = sync_prefs_.GetMemoryPressureWarningCount(); |
| 2455 | 2481 |
| 2456 if (-1 != warning_received) { | 2482 if (-1 != warning_received) { |
| 2457 // -1 means it is new client. | 2483 // -1 means it is new client. |
| 2458 if (!sync_prefs_.DidSyncShutdownCleanly()) { | 2484 if (!sync_prefs_.DidSyncShutdownCleanly()) { |
| 2459 UMA_HISTOGRAM_COUNTS("Sync.MemoryPressureWarningBeforeUncleanShutdown", | 2485 UMA_HISTOGRAM_COUNTS("Sync.MemoryPressureWarningBeforeUncleanShutdown", |
| 2460 warning_received); | 2486 warning_received); |
| 2461 } else { | 2487 } else { |
| 2462 UMA_HISTOGRAM_COUNTS("Sync.MemoryPressureWarningBeforeCleanShutdown", | 2488 UMA_HISTOGRAM_COUNTS("Sync.MemoryPressureWarningBeforeCleanShutdown", |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 2491 | 2517 |
| 2492 DCHECK(startup_controller_->IsSetupInProgress()); | 2518 DCHECK(startup_controller_->IsSetupInProgress()); |
| 2493 startup_controller_->SetSetupInProgress(false); | 2519 startup_controller_->SetSetupInProgress(false); |
| 2494 | 2520 |
| 2495 if (IsBackendInitialized()) | 2521 if (IsBackendInitialized()) |
| 2496 ReconfigureDatatypeManager(); | 2522 ReconfigureDatatypeManager(); |
| 2497 NotifyObservers(); | 2523 NotifyObservers(); |
| 2498 } | 2524 } |
| 2499 | 2525 |
| 2500 } // namespace browser_sync | 2526 } // namespace browser_sync |
| OLD | NEW |