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

Side by Side Diff: content/browser/device_orientation/data_fetcher_shared_memory_base.h

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 #ifndef CONTENT_BROWSER_DEVICE_ORIENTATION_DATA_FETCHER_SHARED_MEMORY_BASE_H_ 5 #ifndef CONTENT_BROWSER_DEVICE_ORIENTATION_DATA_FETCHER_SHARED_MEMORY_BASE_H_
6 #define CONTENT_BROWSER_DEVICE_ORIENTATION_DATA_FETCHER_SHARED_MEMORY_BASE_H_ 6 #define CONTENT_BROWSER_DEVICE_ORIENTATION_DATA_FETCHER_SHARED_MEMORY_BASE_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 27 matching lines...) Expand all
38 // corresponding |consumer_type| parameter. 38 // corresponding |consumer_type| parameter.
39 base::SharedMemoryHandle GetSharedMemoryHandleForProcess( 39 base::SharedMemoryHandle GetSharedMemoryHandleForProcess(
40 ConsumerType consumer_type, base::ProcessHandle process); 40 ConsumerType consumer_type, base::ProcessHandle process);
41 41
42 protected: 42 protected:
43 class PollingThread; 43 class PollingThread;
44 44
45 DataFetcherSharedMemoryBase(); 45 DataFetcherSharedMemoryBase();
46 virtual ~DataFetcherSharedMemoryBase(); 46 virtual ~DataFetcherSharedMemoryBase();
47 47
48 void* GetSharedMemoryBuffer(ConsumerType consumer_type);
49
50 // Returns the message loop of the polling thread. 48 // Returns the message loop of the polling thread.
51 // Returns NULL if there is no polling thread. 49 // Returns NULL if there is no polling thread.
52 base::MessageLoop* GetPollingMessageLoop() const; 50 base::MessageLoop* GetPollingMessageLoop() const;
53 51
54 // If IsPolling() is true this method is called from the |polling_thread_| 52 // If IsPolling() is true this method is called from the |polling_thread_|
55 // at regular intervals. 53 // at regular intervals.
56 virtual void Fetch(unsigned consumer_bitmask); 54 virtual void Fetch(unsigned consumer_bitmask);
57 55
58 // Returns true if this fetcher needs to use a polling thread to 56 // Returns true if this fetcher needs to use a polling thread to
59 // fetch the sensor data. 57 // fetch the sensor data.
60 virtual bool IsPolling() const; 58 virtual bool IsPolling() const;
61 59
62 // Start() method should call InitSharedMemoryBuffer() to get the shared 60 // Start() method should call InitSharedMemoryBuffer() to get the shared
63 // memory pointer. If IsPolling() is true both Start() and Stop() methods 61 // memory pointer. If IsPolling() is true both Start() and Stop() methods
64 // are called from the |polling_thread_|. 62 // are called from the |polling_thread_|.
65 virtual bool Start(ConsumerType consumer_type) = 0; 63 virtual bool Start(ConsumerType consumer_type, void* buffer) = 0;
66 virtual bool Stop(ConsumerType consumer_type) = 0; 64 virtual bool Stop(ConsumerType consumer_type) = 0;
67 65
68 private: 66 private:
69 bool InitAndStartPollingThreadIfNecessary(); 67 bool InitAndStartPollingThreadIfNecessary();
70 base::SharedMemory* GetSharedMemory(ConsumerType consumer_type); 68 base::SharedMemory* GetSharedMemory(ConsumerType consumer_type);
69 void* GetSharedMemoryBuffer(ConsumerType consumer_type);
71 70
72 unsigned started_consumers_; 71 unsigned started_consumers_;
73 72
74 scoped_ptr<PollingThread> polling_thread_; 73 scoped_ptr<PollingThread> polling_thread_;
75 74
76 // Owning pointers. Objects in the map are deleted in dtor. 75 // Owning pointers. Objects in the map are deleted in dtor.
77 typedef std::map<ConsumerType, base::SharedMemory*> SharedMemoryMap; 76 typedef std::map<ConsumerType, base::SharedMemory*> SharedMemoryMap;
78 SharedMemoryMap shared_memory_map_; 77 SharedMemoryMap shared_memory_map_;
79 78
80 DISALLOW_COPY_AND_ASSIGN(DataFetcherSharedMemoryBase); 79 DISALLOW_COPY_AND_ASSIGN(DataFetcherSharedMemoryBase);
81 }; 80 };
82 81
83 } 82 }
84 83
85 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_DATA_FETCHER_SHARED_MEMORY_BASE_H_ 84 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_DATA_FETCHER_SHARED_MEMORY_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698