Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: chrome/browser/extensions/api/sync_file_system/extension_sync_event_observer.cc

Issue 11316133: Added implementation of SyncEventObserver to route events to Javascript Extension. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/extensions/api/sync_file_system/extension_sync_event_ob server.h"
6 #include "chrome/browser/extensions/event_names.h"
7 #include "chrome/browser/extensions/extension_system.h"
8 #include "chrome/browser/sync_file_system/sync_event_observer.h"
9 #include "chrome/common/extensions/api/sync_file_system.h"
10
11 using sync_file_system::SyncEventObserver;
12
13 namespace extensions {
14
15 namespace {
16
17 api::sync_file_system::SyncStateStatus SyncServiceStateEnumToExtensionEnum(
18 SyncEventObserver::SyncServiceState state) {
19 switch(state) {
20 case SyncEventObserver::SYNC_SERVICE_INITIALIZING:
21 return api::sync_file_system::
22 SYNC_FILE_SYSTEM_SYNC_STATE_STATUS_INITIALIZING;
kinuko 2012/11/21 10:59:04 Wow is this line-break allowed? (If it compiles i
calvinlo 2012/11/28 06:01:45 Yes it actually compiles. I wasn't sure how else t
23 case SyncEventObserver::SYNC_SERVICE_RUNNING:
24 return api::sync_file_system::SYNC_FILE_SYSTEM_SYNC_STATE_STATUS_RUNNING;
25 case SyncEventObserver::SYNC_SERVICE_AUTHENTICATION_REQUIRED:
26 return api::sync_file_system::
27 SYNC_FILE_SYSTEM_SYNC_STATE_STATUS_AUTHENTICATION_REQUIRED;
28 case SyncEventObserver::SYNC_SERVICE_TEMPORARY_UNAVAILABLE:
29 return api::sync_file_system::
30 SYNC_FILE_SYSTEM_SYNC_STATE_STATUS_TEMPORARY_UNAVAILABLE;
31 case SyncEventObserver::SYNC_SERVICE_DISABLED:
32 return api::sync_file_system::SYNC_FILE_SYSTEM_SYNC_STATE_STATUS_DISABLED;
33 }
34 NOTREACHED();
35 return api::sync_file_system::SYNC_FILE_SYSTEM_SYNC_STATE_STATUS_NONE;
36 }
37
38 } // namespace
39
40 ExtensionSyncEventObserver::ExtensionSyncEventObserver(
41 std::string extension_id,
42 Profile* profile)
43 : extension_id_(extension_id),
44 profile_(profile) {}
kinuko 2012/11/21 10:59:04 nit: four spaces before ':' is the common pattern
calvinlo 2012/11/28 06:01:45 Done.
45
46 void ExtensionSyncEventObserver::OnSyncStateUpdated(
47 sync_file_system::SyncEventObserver::SyncServiceState state,
48 const std::string& description) {
49 // Convert state and description into SyncState Object
50 api::sync_file_system::SyncState syncState;
kinuko 2012/11/21 10:59:04 syncState -> sync_state while you're in chrome c++
calvinlo 2012/11/28 06:01:45 Done.
51 syncState.service_name = "drive";
kinuko 2012/11/21 10:59:04 Maybe this should be also given in constructor. Or
calvinlo 2012/11/28 06:01:45 Ok, finally able to get back to this. Based on our
kinuko 2012/11/28 07:41:13 I feel that EXTENSION_UNLOADED can surely come lat
52 syncState.state = SyncServiceStateEnumToExtensionEnum(state);
53 syncState.description = description;
54 scoped_ptr<base::ListValue> params(
55 api::sync_file_system::OnSyncStateChanged::Create(syncState));
56
57 // Dispatch the event to the extension
58 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension(
59 extension_id_, event_names::kOnSyncStateChanged, params.Pass(),
60 profile_, GURL());
61 }
62
63 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698