1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file.
4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/extensions/api/music_manager_private/music_manager_private_api.h"
6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/extensions/api/music_manager_private/device_id.h"
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)using content::BrowserThread;
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace {
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)const char kDeviceIdNotSupported[] =
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "Device ID API is not supported on this platform.";
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace extensions {
19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace api {
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)MusicManagerPrivateGetDeviceIdFunction::
22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    MusicManagerPrivateGetDeviceIdFunction() {
23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)MusicManagerPrivateGetDeviceIdFunction::
26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    ~MusicManagerPrivateGetDeviceIdFunction() {
27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)bool MusicManagerPrivateGetDeviceIdFunction::RunImpl() {
30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  DeviceId::GetDeviceId(
32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->extension_id(),
33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      base::Bind(
34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)          &MusicManagerPrivateGetDeviceIdFunction::DeviceIdCallback,
35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)          this));
36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  return true;  // Still processing!
37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void MusicManagerPrivateGetDeviceIdFunction::DeviceIdCallback(
40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    const std::string& device_id) {
41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  bool response;
43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  if (device_id.empty()) {
44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    SetError(kDeviceIdNotSupported);
45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    response = false;
46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  } else {
473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    SetResult(new base::StringValue(device_id));
48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    response = true;
49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  SendResponse(response);
52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} // namespace api
55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} // namespace extensions
56