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

Side by Side Diff: content/browser/screen_orientation/screen_orientation_impl.cc

Issue 2391883006: Mojo-ify implementation of screen orientation locking/unlocking. (Closed)
Patch Set: Codereview update Created 4 years, 1 month 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/screen_orientation/screen_orientation_impl.h"
6
7 #include "base/bind.h"
8 #include "content/public/browser/navigation_details.h"
9 #include "content/public/browser/screen_orientation_provider.h"
10 #include "content/public/browser/web_contents.h"
11
12 namespace content {
13
14 using typename ::blink::mojom::ScreenOrientationLockResult;
15
16 ScreenOrientation::ScreenOrientation(WebContents* web_contents)
17 : web_contents_(web_contents),
blundell 2016/10/25 16:09:26 I think you need to call the WCO constructor here
lunalu1 2016/11/03 23:15:25 Done.
18 binding_(web_contents, this),
19 weak_factory_(this) {
20 provider_.reset(new ScreenOrientationProvider(web_contents));
21 }
22
23 ScreenOrientation::~ScreenOrientation() = default;
24
25 void ScreenOrientation::LockOrientation(
26 blink::WebScreenOrientationLockType orientation,
27 const LockOrientationCallback& callback) {
28 // When a request comes in while another request was already outstanding.
blundell 2016/10/25 16:09:26 nit: I don't think that we need this comment.
lunalu1 2016/11/03 23:15:25 Done.
29 if (!on_result_callback_.is_null()) {
30 NotifyLockResult(ScreenOrientationLockResult::
blundell 2016/10/25 16:09:26 is this formatting thanks to "git cl format"?
lunalu1 2016/11/03 23:15:25 Unfortunately yes. But I will make it less ugly.
31 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED);
32 }
33
34 on_result_callback_ = callback;
35
36 if (!provider_) {
37 NotifyLockResult(ScreenOrientationLockResult::
38 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE);
39 return;
40 }
41
42 provider_->LockOrientation(
43 orientation, base::Bind(&ScreenOrientation::NotifyLockResult,
44 weak_factory_.GetWeakPtr()));
blundell 2016/10/25 16:09:26 This object owns |provider_|, correct? If so there
lunalu1 2016/11/03 23:15:25 Done.
45 }
46
47 void ScreenOrientation::UnlockOrientation() {
48 // Cancel any pending lock request.
49 NotifyLockResult(ScreenOrientationLockResult::
50 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED);
51
52 if (provider_)
53 provider_->UnlockOrientation();
54 }
55
56 void ScreenOrientation::DidNavigateMainFrame(
57 const LoadCommittedDetails& details,
58 const FrameNavigateParams& params) {
59 if (!provider_ || details.is_in_page)
60 return;
61 provider_->UnlockOrientation();
62 }
63
64 void ScreenOrientation::NotifyLockResult(
65 ScreenOrientationLockResult result) {
66 if (on_result_callback_.is_null())
67 return;
68 if (result ==
69 ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS &&
70 binding_.GetCurrentTargetFrame() != web_contents_->GetMainFrame())
blundell 2016/10/25 16:09:26 This still seems strange to me. Can you go through
Ken Rockot(use gerrit already) 2016/10/26 21:59:54 This is correct. It's how WebContentsFrameBindingS
blundell 2016/10/26 23:07:43 I still don't think this is correct. This callback
lunalu1 2016/10/27 22:22:26 Done.
lunalu1 2016/10/27 22:22:26 Seems like Colin is right. With this 4 lines of co
71 return;
72
73 on_result_callback_.Run(result);
74
75 // Reset the callback.
76 on_result_callback_ = LockOrientationCallback();
77 }
78
79 ScreenOrientationProvider*
80 ScreenOrientation::GetScreenOrientationProvider() {
81 return provider_.get();
82 }
83
84 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698