• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/sync/glue/history_delete_directives_data_type_controller.h"
6 
7 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h"
8 #include "chrome/browser/sync/profile_sync_service.h"
9 #include "content/public/browser/browser_thread.h"
10 
11 using content::BrowserThread;
12 
13 namespace browser_sync {
14 
15 HistoryDeleteDirectivesDataTypeController::
HistoryDeleteDirectivesDataTypeController(sync_driver::SyncApiComponentFactory * factory,ProfileSyncService * sync_service)16     HistoryDeleteDirectivesDataTypeController(
17         sync_driver::SyncApiComponentFactory* factory,
18         ProfileSyncService* sync_service)
19     : sync_driver::UIDataTypeController(
20           BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
21           base::Bind(&ChromeReportUnrecoverableError),
22           syncer::HISTORY_DELETE_DIRECTIVES,
23           factory),
24       sync_service_(sync_service) {
25 }
26 
27 HistoryDeleteDirectivesDataTypeController::
~HistoryDeleteDirectivesDataTypeController()28     ~HistoryDeleteDirectivesDataTypeController() {
29 }
30 
ReadyForStart() const31 bool HistoryDeleteDirectivesDataTypeController::ReadyForStart() const {
32   return !sync_service_->EncryptEverythingEnabled();
33 }
34 
StartModels()35 bool HistoryDeleteDirectivesDataTypeController::StartModels() {
36   if (DisableTypeIfNecessary())
37     return false;
38   sync_service_->AddObserver(this);
39   return true;
40 }
41 
StopModels()42 void HistoryDeleteDirectivesDataTypeController::StopModels() {
43   if (sync_service_->HasObserver(this))
44     sync_service_->RemoveObserver(this);
45 }
46 
OnStateChanged()47 void HistoryDeleteDirectivesDataTypeController::OnStateChanged() {
48   DisableTypeIfNecessary();
49 }
50 
DisableTypeIfNecessary()51 bool HistoryDeleteDirectivesDataTypeController::DisableTypeIfNecessary() {
52   if (!sync_service_->ShouldPushChanges())
53     return false;
54 
55   if (ReadyForStart())
56     return false;
57 
58   if (sync_service_->HasObserver(this))
59     sync_service_->RemoveObserver(this);
60   syncer::SyncError error(
61       FROM_HERE,
62       syncer::SyncError::DATATYPE_POLICY_ERROR,
63       "Delete directives not supported with encryption.",
64       type());
65   OnSingleDataTypeUnrecoverableError(error);
66   return true;
67 }
68 
69 }  // namespace browser_sync
70