Chromium Code Reviews| Index: chrome/browser/extensions/api/system_display/display_info_provider.cc |
| diff --git a/chrome/browser/extensions/api/system_display/display_info_provider.cc b/chrome/browser/extensions/api/system_display/display_info_provider.cc |
| index 064688db5694c3865aa6bde3f0ad9c8b48458474..796ecfaff07e9bfa8e1b0d947fcb821f2ca106f1 100644 |
| --- a/chrome/browser/extensions/api/system_display/display_info_provider.cc |
| +++ b/chrome/browser/extensions/api/system_display/display_info_provider.cc |
| @@ -27,11 +27,9 @@ int RotationToDegrees(gfx::Display::Rotation rotation) { |
| return 0; |
| } |
| -// Creates new DisplayUnitInfo struct for |display| and adds it at the end of |
| -// |list|. |
| +// Creates new DisplayUnitInfo struct for |display|. |
| extensions::api::system_display::DisplayUnitInfo* |
| -CreateDisplayUnitInfo(const gfx::Display& display, |
| - int64 primary_display_id) { |
| +CreateDisplayUnitInfo(const gfx::Display& display, int64 primary_display_id) { |
| extensions::api::system_display::DisplayUnitInfo* unit = |
| new extensions::api::system_display::DisplayUnitInfo(); |
| const gfx::Rect& bounds = display.bounds(); |
| @@ -52,59 +50,38 @@ CreateDisplayUnitInfo(const gfx::Display& display, |
| return unit; |
| } |
| -} // namespace |
| +scoped_ptr<DisplayInfoProvider> g_display_info_provider; |
|
Hongbo Min
2013/09/04 06:58:02
It is a common practice to use a base::LazyInstanc
Haojian Wu
2013/09/04 12:21:03
Done.
|
| -DisplayInfoProvider::DisplayInfoProvider() { |
| -} |
| +} // namespace |
| -DisplayInfoProvider::~DisplayInfoProvider() { |
| -} |
| +DisplayInfoProvider::DisplayInfoProvider() {} |
| -// Static member intialization. |
| -base::LazyInstance<scoped_refptr<DisplayInfoProvider > > |
| - DisplayInfoProvider::provider_ = LAZY_INSTANCE_INITIALIZER; |
| +DisplayInfoProvider::~DisplayInfoProvider() {} |
| -const DisplayInfo& DisplayInfoProvider::display_info() const { |
| - return info_; |
| +DisplayInfoProvider* DisplayInfoProvider::Get() { |
| + if (g_display_info_provider.get() == NULL) |
| + g_display_info_provider.reset(new DisplayInfoProvider()); |
| + return g_display_info_provider.get(); |
| } |
| void DisplayInfoProvider::InitializeForTesting( |
| - scoped_refptr<DisplayInfoProvider> provider) { |
| - DCHECK(provider.get() != NULL); |
| - provider_.Get() = provider; |
| -} |
| - |
| -void DisplayInfoProvider::RequestInfo(const RequestInfoCallback& callback) { |
| - bool success = QueryInfo(); |
| - |
| - base::MessageLoopProxy::current()->PostTask( |
| - FROM_HERE, |
| - base::Bind(callback, success)); |
| + DisplayInfoProvider* display_info_provider) { |
| + g_display_info_provider.reset(display_info_provider); |
| } |
| -#if !defined(OS_WIN) |
| -bool DisplayInfoProvider::QueryInfo() { |
| - info_.clear(); |
| - |
| +DisplayInfo DisplayInfoProvider::GetAllDisplaysInfo() { |
| // TODO(scottmg): Native is wrong http://crbug.com/133312 |
| gfx::Screen* screen = gfx::Screen::GetNativeScreen(); |
| int64 primary_id = screen->GetPrimaryDisplay().id(); |
| std::vector<gfx::Display> displays = screen->GetAllDisplays(); |
| + DisplayInfo all_displays; |
| for (int i = 0; i < screen->GetNumDisplays(); ++i) { |
| linked_ptr<extensions::api::system_display::DisplayUnitInfo> unit( |
| CreateDisplayUnitInfo(displays[i], primary_id)); |
| UpdateDisplayUnitInfoForPlatform(displays[i], unit.get()); |
| - info_.push_back(unit); |
| + all_displays.push_back(unit); |
| } |
| - return true; |
| -} |
| -#endif |
| - |
| -// static |
| -DisplayInfoProvider* DisplayInfoProvider::Get() { |
| - if (provider_.Get().get() == NULL) |
| - provider_.Get() = new DisplayInfoProvider(); |
| - return provider_.Get(); |
| + return all_displays; |
| } |
| -} // namespace extensions |
| +} // namespace extensions |