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

Side by Side Diff: chrome/browser/chromeos/extensions/bluetooth_event_router.cc

Issue 9822001: Basic infrastructure for the Bluetooth API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more review comments Created 8 years, 9 months 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/chromeos/extensions/bluetooth_event_router.h"
6
7 #include "base/json/json_writer.h"
8 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h"
9 #include "chrome/browser/extensions/extension_event_names.h"
10 #include "chrome/browser/extensions/extension_event_router.h"
11
12 namespace chromeos {
13
14 ExtensionBluetoothEventRouter::ExtensionBluetoothEventRouter(Profile* profile)
15 : profile_(profile),
16 adapter_(chromeos::BluetoothAdapter::CreateDefaultAdapter()) {
17 DCHECK(profile_);
18 DCHECK(adapter_.get());
19 adapter_->AddObserver(this);
20 }
21
22 ExtensionBluetoothEventRouter::~ExtensionBluetoothEventRouter() {
23 adapter_->RemoveObserver(this);
24 }
25
26 void ExtensionBluetoothEventRouter::AdapterPresentChanged(
27 chromeos::BluetoothAdapter* adapter, bool present) {
28 DCHECK(adapter == adapter_.get());
29 DispatchEvent(extension_event_names::kBluetoothOnAvailabilityChanged,
30 present);
31 }
32
33 void ExtensionBluetoothEventRouter::AdapterPoweredChanged(
34 chromeos::BluetoothAdapter* adapter, bool has_power) {
35 DCHECK(adapter == adapter_.get());
36 DispatchEvent(extension_event_names::kBluetoothOnPowerChanged, has_power);
37 }
38
39 void ExtensionBluetoothEventRouter::DispatchEvent(
40 const char* event_name, bool value) {
41 ListValue args;
42 args.Append(Value::CreateBooleanValue(value));
43 std::string json_args;
44 base::JSONWriter::Write(&args, &json_args);
45
46 profile_->GetExtensionEventRouter()->DispatchEventToRenderers(
47 event_name, json_args, NULL, GURL());
48 }
49
50 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698