#ifndef CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_SYNCED_NOTIFICATION_APP_INFO_SERVICE_H_
#define CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_SYNCED_NOTIFICATION_APP_INFO_SERVICE_H_
#include <string>
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_vector.h"
#include "base/threading/thread_checker.h"
#include "chrome/browser/notifications/sync_notifier/synced_notification_app_info.h"
#include "components/keyed_service/core/keyed_service.h"
#include "sync/api/syncable_service.h"
class NotificationUIManager;
class Profile;
namespace sync_pb {
class SyncedNotificationAppInfo;
}
namespace notifier {
struct SyncedNotificationSendingServiceSettingsData {
SyncedNotificationSendingServiceSettingsData(
std::string settings_display_name,
gfx::Image settings_icon,
message_center::NotifierId notifier_id);
std::string settings_display_name;
gfx::Image settings_icon;
message_center::NotifierId notifier_id;
};
class ChromeNotifierService;
class SyncedNotificationAppInfoService : public syncer::SyncableService,
public KeyedService {
public:
explicit SyncedNotificationAppInfoService(Profile* profile);
virtual ~SyncedNotificationAppInfoService();
virtual void Shutdown() OVERRIDE;
virtual syncer::SyncMergeResult MergeDataAndStartSyncing(
syncer::ModelType type,
const syncer::SyncDataList& initial_sync_data,
scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE;
virtual void StopSyncing(syncer::ModelType type) OVERRIDE;
virtual syncer::SyncError ProcessSyncChanges(
const tracked_objects::Location& from_here,
const syncer::SyncChangeList& change_list) OVERRIDE;
virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type)
const OVERRIDE;
void ProcessIncomingAppInfoProtobuf(
const sync_pb::SyncedNotificationAppInfo& app_info);
void ProcessRemovedAppInfoProtobuf(
const sync_pb::SyncedNotificationAppInfo& app_info);
virtual void OnBitmapFetchesDone(std::vector<std::string> added_app_ids,
std::vector<std::string> removed_app_ids);
scoped_ptr<SyncedNotificationAppInfo>
CreateSyncedNotificationAppInfoFromProtobuf(
const sync_pb::SyncedNotificationAppInfo& app_info);
SyncedNotificationAppInfo* FindSyncedNotificationAppInfoByName(
const std::string& name);
SyncedNotificationAppInfo* FindSyncedNotificationAppInfoByAppId(
const std::string& app_id);
std::string FindSendingServiceNameFromAppId(const std::string app_id);
std::vector<SyncedNotificationSendingServiceSettingsData>
GetAllSendingServiceSettingsData();
void set_chrome_notifier_service(ChromeNotifierService* notifier) {
chrome_notifier_service_ = notifier;
}
void AddForTest(
scoped_ptr<notifier::SyncedNotificationAppInfo> sending_service_info) {
Add(sending_service_info.Pass());
}
static void set_avoid_bitmap_fetching_for_test(bool avoid) {
avoid_bitmap_fetching_for_test_ = avoid;
}
private:
void Add(
scoped_ptr<notifier::SyncedNotificationAppInfo> sending_service_info);
void FreeSyncedNotificationAppInfoByName(const std::string& name);
size_t sending_service_infos_size() { return sending_service_infos_.size(); }
Profile* const profile_;
base::ThreadChecker thread_checker_;
ScopedVector<notifier::SyncedNotificationAppInfo> sending_service_infos_;
syncer::SyncData sync_data_;
static bool avoid_bitmap_fetching_for_test_;
ChromeNotifierService* chrome_notifier_service_;
friend class SyncedNotificationAppInfoServiceTest;
FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
MergeDataAndStartSyncingTest);
FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
ProcessSyncChangesEmptyModel);
FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
ProcessSyncChangesNonEmptyModel);
FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
FindSyncedNotificationAppInfoByNameTest);
FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
FindSyncedNotificationAppInfoByNameTestTest);
FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
FreeSyncedNotificationAppInfoByNameTest);
FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
CreateSyncedNotificationAppInfoFromProtobufTest);
FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
ProcessIncomingAppInfoProtobufAddTest);
FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
ProcessIncomingAppInfoProtobufUpdateTest);
FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
ProcessRemovedAppInfoProtobufTest);
DISALLOW_COPY_AND_ASSIGN(SyncedNotificationAppInfoService);
};
}
#endif