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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_THEMES_THEME_SYNCABLE_SERVICE_H_
6 #define CHROME_BROWSER_THEMES_THEME_SYNCABLE_SERVICE_H_
8 #include "base/gtest_prod_util.h"
9 #include "base/threading/thread_checker.h"
10 #include "sync/api/sync_change.h"
11 #include "sync/api/sync_data.h"
12 #include "sync/api/sync_error_factory.h"
13 #include "sync/api/sync_error.h"
14 #include "sync/api/syncable_service.h"
18 class ThemeSyncableServiceTest
;
24 class ThemeSyncableService
: public syncer::SyncableService
{
26 ThemeSyncableService(Profile
* profile
, // Same profile used by theme_service.
27 ThemeService
* theme_service
);
28 virtual ~ThemeSyncableService();
30 static syncer::ModelType
model_type() { return syncer::THEMES
; }
32 // Called by ThemeService when user changes theme.
35 // syncer::SyncableService implementation.
36 virtual syncer::SyncMergeResult
MergeDataAndStartSyncing(
37 syncer::ModelType type
,
38 const syncer::SyncDataList
& initial_sync_data
,
39 scoped_ptr
<syncer::SyncChangeProcessor
> sync_processor
,
40 scoped_ptr
<syncer::SyncErrorFactory
> error_handler
) OVERRIDE
;
41 virtual void StopSyncing(syncer::ModelType type
) OVERRIDE
;
42 virtual syncer::SyncDataList
GetAllSyncData(
43 syncer::ModelType type
) const OVERRIDE
;
44 virtual syncer::SyncError
ProcessSyncChanges(
45 const tracked_objects::Location
& from_here
,
46 const syncer::SyncChangeList
& change_list
) OVERRIDE
;
48 // Client tag and tile of theme node in sync.
49 static const char kCurrentThemeClientTag
[];
50 static const char kCurrentThemeNodeTitle
[];
53 static bool AreThemeSpecificsEqual(
54 const sync_pb::ThemeSpecifics
& a
,
55 const sync_pb::ThemeSpecifics
& b
,
56 bool is_system_theme_distinct_from_default_theme
);
58 // Set theme from theme specifics in |sync_data| using
59 // SetCurrentThemeFromThemeSpecifics() if it's different from |current_specs|.
60 void MaybeSetTheme(const sync_pb::ThemeSpecifics
& current_specs
,
61 const syncer::SyncData
& sync_data
);
63 void SetCurrentThemeFromThemeSpecifics(
64 const sync_pb::ThemeSpecifics
& theme_specifics
);
66 // If the current theme is syncable, fills in the passed |theme_specifics|
67 // structure based on the currently applied theme and returns |true|.
68 // Otherwise returns |false|.
69 bool GetThemeSpecificsFromCurrentTheme(
70 sync_pb::ThemeSpecifics
* theme_specifics
) const;
72 // Updates theme specifics in sync to |theme_specifics|.
73 syncer::SyncError
ProcessNewTheme(
74 syncer::SyncChange::SyncChangeType change_type
,
75 const sync_pb::ThemeSpecifics
& theme_specifics
);
77 Profile
* const profile_
;
78 ThemeService
* const theme_service_
;
80 scoped_ptr
<syncer::SyncChangeProcessor
> sync_processor_
;
81 scoped_ptr
<syncer::SyncErrorFactory
> sync_error_handler_
;
83 // Persist use_system_theme_by_default for platforms that use it, even if
85 bool use_system_theme_by_default_
;
87 base::ThreadChecker thread_checker_
;
89 FRIEND_TEST_ALL_PREFIXES(ThemeSyncableServiceTest
, AreThemeSpecificsEqual
);
91 DISALLOW_COPY_AND_ASSIGN(ThemeSyncableService
);
94 #endif // CHROME_BROWSER_THEMES_THEME_SYNCABLE_SERVICE_H_