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

Side by Side Diff: content/browser/device_orientation/data_fetcher_shared_memory_default.cc

Issue 23441047: Fix race condition in DataFetcherSharedMemoryBase (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "data_fetcher_shared_memory.h" 5 #include "data_fetcher_shared_memory.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/common/device_motion_hardware_buffer.h" 8 #include "content/common/device_motion_hardware_buffer.h"
9 #include "content/common/device_orientation/device_orientation_hardware_buffer.h " 9 #include "content/common/device_orientation/device_orientation_hardware_buffer.h "
10 10
11 namespace { 11 namespace {
12 12
13 static bool SetMotionBuffer(content::DeviceMotionHardwareBuffer* buffer, 13 static bool SetMotionBuffer(content::DeviceMotionHardwareBuffer* buffer,
14 bool enabled) { 14 bool enabled) {
15 DCHECK(buffer); 15 if (!buffer)
16 return false;
16 buffer->seqlock.WriteBegin(); 17 buffer->seqlock.WriteBegin();
17 buffer->data.allAvailableSensorsAreActive = enabled; 18 buffer->data.allAvailableSensorsAreActive = enabled;
18 buffer->seqlock.WriteEnd(); 19 buffer->seqlock.WriteEnd();
19 return true; 20 return true;
20 } 21 }
21 22
22 } 23 }
23 24
24 namespace content { 25 namespace content {
25 26
26 DataFetcherSharedMemory::DataFetcherSharedMemory() { 27 DataFetcherSharedMemory::DataFetcherSharedMemory() {
27 } 28 }
28 29
29 DataFetcherSharedMemory::~DataFetcherSharedMemory() { 30 DataFetcherSharedMemory::~DataFetcherSharedMemory() {
30 } 31 }
31 32
32 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type) { 33 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) {
33 void* buffer = GetSharedMemoryBuffer(consumer_type);
34 DCHECK(buffer); 34 DCHECK(buffer);
35 35
36 switch (consumer_type) { 36 switch (consumer_type) {
37 case CONSUMER_TYPE_MOTION: 37 case CONSUMER_TYPE_MOTION:
38 return SetMotionBuffer( 38 motion_buffer_ = static_cast<DeviceMotionHardwareBuffer*>(buffer);
39 static_cast<DeviceMotionHardwareBuffer*>(buffer), true); 39 return SetMotionBuffer(motion_buffer_, true);
40 case CONSUMER_TYPE_ORIENTATION: 40 case CONSUMER_TYPE_ORIENTATION:
41 NOTIMPLEMENTED(); 41 NOTIMPLEMENTED();
42 break; 42 break;
43 default: 43 default:
44 NOTREACHED(); 44 NOTREACHED();
45 } 45 }
46 return false; 46 return false;
47 } 47 }
48 48
49 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) { 49 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) {
50 void* buffer = GetSharedMemoryBuffer(consumer_type);
51 DCHECK(buffer);
52 50
53 switch (consumer_type) { 51 switch (consumer_type) {
54 case CONSUMER_TYPE_MOTION: 52 case CONSUMER_TYPE_MOTION:
55 return SetMotionBuffer( 53 return SetMotionBuffer(motion_buffer_, false);
56 static_cast<DeviceMotionHardwareBuffer*>(buffer), false);
57 case CONSUMER_TYPE_ORIENTATION: 54 case CONSUMER_TYPE_ORIENTATION:
58 NOTIMPLEMENTED(); 55 NOTIMPLEMENTED();
59 break; 56 break;
60 default: 57 default:
61 NOTREACHED(); 58 NOTREACHED();
62 } 59 }
63 return false; 60 return false;
64 } 61 }
65 62
66 } // namespace content 63 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698