| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/device_orientation/data_fetcher_impl_win.h" | 5 #include "content/browser/device_orientation/data_fetcher_impl_win.h" |
| 6 | 6 |
| 7 #include <InitGuid.h> | 7 #include <InitGuid.h> |
| 8 #include <PortableDeviceTypes.h> | 8 #include <PortableDeviceTypes.h> |
| 9 #include <Sensors.h> | 9 #include <Sensors.h> |
| 10 | 10 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 STDMETHODIMP OnStateChanged(ISensor* sensor, SensorState state) OVERRIDE { | 94 STDMETHODIMP OnStateChanged(ISensor* sensor, SensorState state) OVERRIDE { |
| 95 return S_OK; | 95 return S_OK; |
| 96 } | 96 } |
| 97 | 97 |
| 98 private: | 98 private: |
| 99 DataFetcherImplWin* const fetcher_; | 99 DataFetcherImplWin* const fetcher_; |
| 100 | 100 |
| 101 DISALLOW_COPY_AND_ASSIGN(SensorEventSink); | 101 DISALLOW_COPY_AND_ASSIGN(SensorEventSink); |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 DataFetcherImplWin* DataFetcherImplWin::instance() { |
| 105 CR_DEFINE_STATIC_LOCAL(DataFetcherImplWin, s_data_fetcher, ()); |
| 106 return &s_data_fetcher; |
| 107 } |
| 108 |
| 104 // Create a DataFetcherImplWin object and return NULL if no valid sensor found. | 109 // Create a DataFetcherImplWin object and return NULL if no valid sensor found. |
| 105 // static | 110 // static |
| 106 DataFetcher* DataFetcherImplWin::Create() { | 111 DataFetcher* DataFetcherImplWin::Create() { |
| 107 scoped_ptr<DataFetcherImplWin> fetcher(new DataFetcherImplWin); | 112 DataFetcherImplWin* fetcher = DataFetcherImplWin::instance(); |
| 108 if (fetcher->Initialize()) | 113 if (fetcher->Initialize()) |
| 109 return fetcher.release(); | 114 return fetcher; |
| 110 | 115 |
| 111 LOG(ERROR) << "DataFetcherImplWin::Initialize failed!"; | 116 LOG(ERROR) << "DataFetcherImplWin::Initialize failed!"; |
| 112 return NULL; | 117 return NULL; |
| 113 } | 118 } |
| 114 | 119 |
| 115 DataFetcherImplWin::~DataFetcherImplWin() { | 120 DataFetcherImplWin::~DataFetcherImplWin() { |
| 116 if (sensor_) | 121 Stop(); |
| 117 sensor_->SetEventSink(NULL); | |
| 118 } | 122 } |
| 119 | 123 |
| 120 DataFetcherImplWin::DataFetcherImplWin() { | 124 DataFetcherImplWin::DataFetcherImplWin() { |
| 121 } | 125 } |
| 122 | 126 |
| 127 void DataFetcherImplWin::Stop() { |
| 128 if (sensor_) |
| 129 sensor_->SetEventSink(NULL); |
| 130 } |
| 131 |
| 123 void DataFetcherImplWin::OnOrientationData(Orientation* orientation) { | 132 void DataFetcherImplWin::OnOrientationData(Orientation* orientation) { |
| 124 // This method is called on Windows sensor thread. | 133 // This method is called on Windows sensor thread. |
| 125 base::AutoLock autolock(next_orientation_lock_); | 134 base::AutoLock autolock(next_orientation_lock_); |
| 126 next_orientation_ = orientation; | 135 next_orientation_ = orientation; |
| 127 } | 136 } |
| 128 | 137 |
| 129 const DeviceData* DataFetcherImplWin::GetDeviceData(DeviceData::Type type) { | 138 const DeviceData* DataFetcherImplWin::GetDeviceData(DeviceData::Type type) { |
| 130 if (type != DeviceData::kTypeOrientation) | 139 if (type != DeviceData::kTypeOrientation) |
| 131 return NULL; | 140 return NULL; |
| 132 return GetOrientation(); | 141 return GetOrientation(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 return false; | 193 return false; |
| 185 | 194 |
| 186 hr = sensor_->SetEventSink(sensor_events); | 195 hr = sensor_->SetEventSink(sensor_events); |
| 187 if (FAILED(hr)) | 196 if (FAILED(hr)) |
| 188 return false; | 197 return false; |
| 189 | 198 |
| 190 return true; | 199 return true; |
| 191 } | 200 } |
| 192 | 201 |
| 193 } // namespace content | 202 } // namespace content |
| OLD | NEW |