Split projecting configuration into separate delegate

Moved projecting configuration into separate delegate. Since Delegate deals only
with display configuration, I've also renamed it to NativeDisplayDelegate to
better reflect its purpose.

BUG=333413

Review URL: https://codereview.chromium.org/154033004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@250205 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chromeos/display/real_output_configurator_delegate.cc b/chromeos/display/native_display_delegate_x11.cc
similarity index 76%
rename from chromeos/display/real_output_configurator_delegate.cc
rename to chromeos/display/native_display_delegate_x11.cc
index ca816bc3..22d0e1ef 100644
--- a/chromeos/display/real_output_configurator_delegate.cc
+++ b/chromeos/display/native_display_delegate_x11.cc
@@ -1,8 +1,8 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "chromeos/display/real_output_configurator_delegate.h"
+#include "chromeos/display/native_display_delegate_x11.h"
 
 #include <X11/Xatom.h>
 #include <X11/Xlib.h>
@@ -15,8 +15,6 @@
 #include "base/message_loop/message_pump_x11.h"
 #include "base/x11/edid_parser_x11.h"
 #include "base/x11/x11_error_tracker.h"
-#include "chromeos/dbus/dbus_thread_manager.h"
-#include "chromeos/dbus/power_manager_client.h"
 #include "chromeos/display/output_util.h"
 
 namespace chromeos {
@@ -49,44 +47,40 @@
 
 }  // namespace
 
-RealOutputConfiguratorDelegate::RealOutputConfiguratorDelegate()
+NativeDisplayDelegateX11::NativeDisplayDelegateX11()
     : display_(base::MessagePumpX11::GetDefaultXDisplay()),
       window_(DefaultRootWindow(display_)),
-      screen_(NULL) {
-}
+      screen_(NULL) {}
 
-RealOutputConfiguratorDelegate::~RealOutputConfiguratorDelegate() {
-}
+NativeDisplayDelegateX11::~NativeDisplayDelegateX11() {}
 
-void RealOutputConfiguratorDelegate::InitXRandRExtension(int* event_base) {
+void NativeDisplayDelegateX11::InitXRandRExtension(int* event_base) {
   int error_base_ignored = 0;
   XRRQueryExtension(display_, event_base, &error_base_ignored);
 }
 
-void RealOutputConfiguratorDelegate::UpdateXRandRConfiguration(
+void NativeDisplayDelegateX11::UpdateXRandRConfiguration(
     const base::NativeEvent& event) {
   XRRUpdateConfiguration(event);
 }
 
-void RealOutputConfiguratorDelegate::GrabServer() {
+void NativeDisplayDelegateX11::GrabServer() {
   CHECK(!screen_) << "Server already grabbed";
   XGrabServer(display_);
   screen_ = XRRGetScreenResources(display_, window_);
   CHECK(screen_);
 }
 
-void RealOutputConfiguratorDelegate::UngrabServer() {
+void NativeDisplayDelegateX11::UngrabServer() {
   CHECK(screen_) << "Server not grabbed";
   XRRFreeScreenResources(screen_);
   screen_ = NULL;
   XUngrabServer(display_);
 }
 
-void RealOutputConfiguratorDelegate::SyncWithServer() {
-  XSync(display_, 0);
-}
+void NativeDisplayDelegateX11::SyncWithServer() { XSync(display_, 0); }
 
-void RealOutputConfiguratorDelegate::SetBackgroundColor(uint32 color_argb) {
+void NativeDisplayDelegateX11::SetBackgroundColor(uint32 color_argb) {
   // Configuring CRTCs/Framebuffer clears the boot screen image.  Set the
   // same background color while configuring the display to minimize the
   // duration of black screen at boot time. The background is filled with
@@ -105,13 +99,13 @@
   XFreeColors(display_, colormap, &color.pixel, 1, 0);
 }
 
-void RealOutputConfiguratorDelegate::ForceDPMSOn() {
+void NativeDisplayDelegateX11::ForceDPMSOn() {
   CHECK(DPMSEnable(display_));
   CHECK(DPMSForceLevel(display_, DPMSModeOn));
 }
 
 std::vector<OutputConfigurator::OutputSnapshot>
-RealOutputConfiguratorDelegate::GetOutputs() {
+NativeDisplayDelegateX11::GetOutputs() {
   CHECK(screen_) << "Server not grabbed";
 
   std::vector<OutputConfigurator::OutputSnapshot> outputs;
@@ -121,11 +115,10 @@
     RROutput output_id = screen_->outputs[i];
     XRROutputInfo* output_info = XRRGetOutputInfo(display_, screen_, output_id);
     if (output_info->connection == RR_Connected) {
-      OutputConfigurator::OutputSnapshot output = InitOutputSnapshot(
-          output_id, output_info, &last_used_crtc, i);
+      OutputConfigurator::OutputSnapshot output =
+          InitOutputSnapshot(output_id, output_info, &last_used_crtc, i);
       VLOG(2) << "Found display " << outputs.size() << ":"
-              << " output=" << output.output
-              << " crtc=" << output.crtc
+              << " output=" << output.output << " crtc=" << output.crtc
               << " current_mode=" << output.current_mode;
       outputs.push_back(output);
     }
@@ -135,25 +128,20 @@
   return outputs;
 }
 
-void RealOutputConfiguratorDelegate::AddOutputMode(RROutput output,
-                                                   RRMode mode) {
+void NativeDisplayDelegateX11::AddOutputMode(RROutput output, RRMode mode) {
   CHECK(screen_) << "Server not grabbed";
   VLOG(1) << "AddOutputMode: output=" << output << " mode=" << mode;
   XRRAddOutputMode(display_, output, mode);
 }
 
-bool RealOutputConfiguratorDelegate::ConfigureCrtc(
-    RRCrtc crtc,
-    RRMode mode,
-    RROutput output,
-    int x,
-    int y) {
+bool NativeDisplayDelegateX11::ConfigureCrtc(RRCrtc crtc,
+                                             RRMode mode,
+                                             RROutput output,
+                                             int x,
+                                             int y) {
   CHECK(screen_) << "Server not grabbed";
-  VLOG(1) << "ConfigureCrtc: crtc=" << crtc
-          << " mode=" << mode
-          << " output=" << output
-          << " x=" << x
-          << " y=" << y;
+  VLOG(1) << "ConfigureCrtc: crtc=" << crtc << " mode=" << mode
+          << " output=" << output << " x=" << x << " y=" << y;
   // Xrandr.h is full of lies. XRRSetCrtcConfig() is defined as returning a
   // Status, which is typically 0 for failure and 1 for success. In
   // actuality it returns a RRCONFIGSTATUS, which uses 0 for success.
@@ -169,7 +157,7 @@
                           (output && mode) ? 1 : 0) == RRSetConfigSuccess;
 }
 
-void RealOutputConfiguratorDelegate::CreateFrameBuffer(
+void NativeDisplayDelegateX11::CreateFrameBuffer(
     int width,
     int height,
     const std::vector<OutputConfigurator::OutputSnapshot>& outputs) {
@@ -178,7 +166,7 @@
   int current_height = DisplayHeight(display_, DefaultScreen(display_));
   VLOG(1) << "CreateFrameBuffer: new=" << width << "x" << height
           << " current=" << current_width << "x" << current_height;
-  if (width ==  current_width && height == current_height)
+  if (width == current_width && height == current_height)
     return;
 
   DestroyUnusedCrtcs(outputs);
@@ -187,13 +175,7 @@
   XRRSetScreenSize(display_, window_, width, height, mm_width, mm_height);
 }
 
-void RealOutputConfiguratorDelegate::SendProjectingStateToPowerManager(
-    bool projecting) {
-  chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
-      SetIsProjecting(projecting);
-}
-
-bool RealOutputConfiguratorDelegate::InitModeInfo(
+bool NativeDisplayDelegateX11::InitModeInfo(
     RRMode mode,
     OutputConfigurator::ModeInfo* mode_info) {
   DCHECK(mode_info);
@@ -209,9 +191,9 @@
       mode_info->height = info.height;
       mode_info->interlaced = info.modeFlags & RR_Interlace;
       if (info.hTotal && info.vTotal) {
-        mode_info->refresh_rate = static_cast<float>(info.dotClock) /
-            (static_cast<float>(info.hTotal) *
-             static_cast<float>(info.vTotal));
+        mode_info->refresh_rate =
+            static_cast<float>(info.dotClock) /
+            (static_cast<float>(info.hTotal) * static_cast<float>(info.vTotal));
       } else {
         mode_info->refresh_rate = 0.0f;
       }
@@ -221,8 +203,7 @@
   return false;
 }
 
-OutputConfigurator::OutputSnapshot
-RealOutputConfiguratorDelegate::InitOutputSnapshot(
+OutputConfigurator::OutputSnapshot NativeDisplayDelegateX11::InitOutputSnapshot(
     RROutput id,
     XRROutputInfo* info,
     RRCrtc* last_used_crtc,
@@ -290,8 +271,7 @@
   return output;
 }
 
-bool RealOutputConfiguratorDelegate::GetHDCPState(RROutput id,
-                                                  HDCPState* state) {
+bool NativeDisplayDelegateX11::GetHDCPState(RROutput id, HDCPState* state) {
   unsigned char* values = NULL;
   int actual_format = 0;
   unsigned long nitems = 0;
@@ -304,9 +284,18 @@
   bool ok = true;
   // TODO(kcwu): Move this to x11_util (similar method calls in this file and
   // output_util.cc)
-  success = XRRGetOutputProperty(display_, id, prop, 0, 100, False,
-                                 False, AnyPropertyType, &actual_type,
-                                 &actual_format, &nitems, &bytes_after,
+  success = XRRGetOutputProperty(display_,
+                                 id,
+                                 prop,
+                                 0,
+                                 100,
+                                 False,
+                                 False,
+                                 AnyPropertyType,
+                                 &actual_type,
+                                 &actual_format,
+                                 &nitems,
+                                 &bytes_after,
                                  &values);
   if (actual_type == None) {
     LOG(ERROR) << "Property '" << kContentProtectionAtomName
@@ -317,15 +306,15 @@
     Atom value = reinterpret_cast<Atom*>(values)[0];
     if (value == XInternAtom(display_, kProtectionUndesiredAtomName, False)) {
       *state = HDCP_STATE_UNDESIRED;
-    } else if (value == XInternAtom(display_, kProtectionDesiredAtomName,
-                                    False)) {
+    } else if (value ==
+               XInternAtom(display_, kProtectionDesiredAtomName, False)) {
       *state = HDCP_STATE_DESIRED;
-    } else if (value == XInternAtom(display_, kProtectionEnabledAtomName,
-                                    False)) {
+    } else if (value ==
+               XInternAtom(display_, kProtectionEnabledAtomName, False)) {
       *state = HDCP_STATE_ENABLED;
     } else {
-      LOG(ERROR) << "Unknown " << kContentProtectionAtomName << " value: "
-                 << value;
+      LOG(ERROR) << "Unknown " << kContentProtectionAtomName
+                 << " value: " << value;
       ok = false;
     }
   } else {
@@ -339,8 +328,7 @@
   return ok;
 }
 
-bool RealOutputConfiguratorDelegate::SetHDCPState(RROutput id,
-                                                  HDCPState state) {
+bool NativeDisplayDelegateX11::SetHDCPState(RROutput id, HDCPState state) {
   Atom name = XInternAtom(display_, kContentProtectionAtomName, False);
   Atom value = None;
   switch (state) {
@@ -356,8 +344,8 @@
   }
   base::X11ErrorTracker err_tracker;
   unsigned char* data = reinterpret_cast<unsigned char*>(&value);
-  XRRChangeOutputProperty(display_, id, name, XA_ATOM, 32,
-                          PropModeReplace, data, 1);
+  XRRChangeOutputProperty(
+      display_, id, name, XA_ATOM, 32, PropModeReplace, data, 1);
   if (err_tracker.FoundNewError()) {
     LOG(ERROR) << "XRRChangeOutputProperty failed";
     return false;
@@ -366,7 +354,7 @@
   }
 }
 
-void RealOutputConfiguratorDelegate::DestroyUnusedCrtcs(
+void NativeDisplayDelegateX11::DestroyUnusedCrtcs(
     const std::vector<OutputConfigurator::OutputSnapshot>& outputs) {
   CHECK(screen_) << "Server not grabbed";
   // Setting the screen size will fail if any CRTC doesn't fit afterwards.
@@ -387,7 +375,9 @@
     RROutput output = None;
     const OutputConfigurator::ModeInfo* mode_info = NULL;
     for (std::vector<OutputConfigurator::OutputSnapshot>::const_iterator it =
-         outputs.begin(); it != outputs.end(); ++it) {
+             outputs.begin();
+         it != outputs.end();
+         ++it) {
       if (crtc == it->crtc) {
         mode = it->current_mode;
         output = it->output;
@@ -414,8 +404,7 @@
   }
 }
 
-bool RealOutputConfiguratorDelegate::IsOutputAspectPreservingScaling(
-    RROutput id) {
+bool NativeDisplayDelegateX11::IsOutputAspectPreservingScaling(RROutput id) {
   bool ret = false;
 
   Atom scaling_prop = XInternAtom(display_, "scaling mode", False);
@@ -435,11 +424,21 @@
       Atom actual_type;
       int success;
 
-      success = XRRGetOutputProperty(display_, id, prop, 0, 100, False, False,
-          AnyPropertyType, &actual_type, &actual_format, &nitems,
-          &bytes_after, &values);
-      if (success == Success && actual_type == XA_ATOM &&
-          actual_format == 32 && nitems == 1) {
+      success = XRRGetOutputProperty(display_,
+                                     id,
+                                     prop,
+                                     0,
+                                     100,
+                                     False,
+                                     False,
+                                     AnyPropertyType,
+                                     &actual_type,
+                                     &actual_format,
+                                     &nitems,
+                                     &bytes_after,
+                                     &values);
+      if (success == Success && actual_type == XA_ATOM && actual_format == 32 &&
+          nitems == 1) {
         Atom value = reinterpret_cast<Atom*>(values)[0];
         if (full_aspect_atom == value)
           ret = true;
diff --git a/chromeos/display/real_output_configurator_delegate.h b/chromeos/display/native_display_delegate_x11.h
similarity index 68%
rename from chromeos/display/real_output_configurator_delegate.h
rename to chromeos/display/native_display_delegate_x11.h
index 7c7d62b..fbce154 100644
--- a/chromeos/display/real_output_configurator_delegate.h
+++ b/chromeos/display/native_display_delegate_x11.h
@@ -1,9 +1,9 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef CHROMEOS_DISPLAY_REAL_OUTPUT_CONFIGURATOR_DELEGATE_H_
-#define CHROMEOS_DISPLAY_REAL_OUTPUT_CONFIGURATOR_DELEGATE_H_
+#ifndef CHROMEOS_DISPLAY_NATIVE_DISPLAY_DELEGATE_X11_H_
+#define CHROMEOS_DISPLAY_NATIVE_DISPLAY_DELEGATE_X11_H_
 
 #include <vector>
 
@@ -22,15 +22,16 @@
 
 namespace chromeos {
 
-class RealOutputConfiguratorDelegate : public OutputConfigurator::Delegate {
+class NativeDisplayDelegateX11
+    : public OutputConfigurator::NativeDisplayDelegate {
  public:
-  RealOutputConfiguratorDelegate();
-  virtual ~RealOutputConfiguratorDelegate();
+  NativeDisplayDelegateX11();
+  virtual ~NativeDisplayDelegateX11();
 
   // OutputConfigurator::Delegate overrides:
   virtual void InitXRandRExtension(int* event_base) OVERRIDE;
-  virtual void UpdateXRandRConfiguration(
-      const base::NativeEvent& event) OVERRIDE;
+  virtual void UpdateXRandRConfiguration(const base::NativeEvent& event)
+      OVERRIDE;
   virtual void GrabServer() OVERRIDE;
   virtual void UngrabServer() OVERRIDE;
   virtual void SyncWithServer() OVERRIDE;
@@ -38,17 +39,15 @@
   virtual void ForceDPMSOn() OVERRIDE;
   virtual std::vector<OutputConfigurator::OutputSnapshot> GetOutputs() OVERRIDE;
   virtual void AddOutputMode(RROutput output, RRMode mode) OVERRIDE;
-  virtual bool ConfigureCrtc(
-      RRCrtc crtc,
-      RRMode mode,
-      RROutput output,
-      int x,
-      int y) OVERRIDE;
+  virtual bool ConfigureCrtc(RRCrtc crtc,
+                             RRMode mode,
+                             RROutput output,
+                             int x,
+                             int y) OVERRIDE;
   virtual void CreateFrameBuffer(
       int width,
       int height,
       const std::vector<OutputConfigurator::OutputSnapshot>& outputs) OVERRIDE;
-  virtual void SendProjectingStateToPowerManager(bool projecting) OVERRIDE;
   virtual bool GetHDCPState(RROutput id, HDCPState* state) OVERRIDE;
   virtual bool SetHDCPState(RROutput id, HDCPState state) OVERRIDE;
 
@@ -60,11 +59,10 @@
   // Helper method for GetOutputs() that returns an OutputSnapshot struct based
   // on the passed-in information. Further initialization is required (e.g.
   // |selected_mode|, |mirror_mode|, and |touch_device_id|).
-  OutputConfigurator::OutputSnapshot InitOutputSnapshot(
-      RROutput id,
-      XRROutputInfo* info,
-      RRCrtc* last_used_crtc,
-      int index);
+  OutputConfigurator::OutputSnapshot InitOutputSnapshot(RROutput id,
+                                                        XRROutputInfo* info,
+                                                        RRCrtc* last_used_crtc,
+                                                        int index);
 
   // Destroys unused CRTCs and parks used CRTCs in a way which allows a
   // framebuffer resize. This is faster than turning them off, resizing,
@@ -81,9 +79,9 @@
   // Initialized when the server is grabbed and freed when it's ungrabbed.
   XRRScreenResources* screen_;
 
-  DISALLOW_COPY_AND_ASSIGN(RealOutputConfiguratorDelegate);
+  DISALLOW_COPY_AND_ASSIGN(NativeDisplayDelegateX11);
 };
 
 }  // namespace chromeos
 
-#endif  // CHROMEOS_DISPLAY_REAL_OUTPUT_CONFIGURATOR_DELEGATE_H_
+#endif  // CHROMEOS_DISPLAY_NATIVE_DISPLAY_DELEGATE_X11_H_
diff --git a/chromeos/display/output_configurator.cc b/chromeos/display/output_configurator.cc
index 327d243..22b9fb36 100644
--- a/chromeos/display/output_configurator.cc
+++ b/chromeos/display/output_configurator.cc
@@ -14,8 +14,8 @@
 #include "base/strings/stringprintf.h"
 #include "base/sys_info.h"
 #include "base/time/time.h"
+#include "chromeos/display/native_display_delegate_x11.h"
 #include "chromeos/display/output_util.h"
-#include "chromeos/display/real_output_configurator_delegate.h"
 #include "chromeos/display/touchscreen_delegate_x11.h"
 
 namespace chromeos {
@@ -239,14 +239,13 @@
       xrandr_event_base_(0),
       output_state_(STATE_INVALID),
       power_state_(DISPLAY_POWER_ALL_ON),
-      next_output_protection_client_id_(1),
-      casting_session_count_(0) {
-}
+      next_output_protection_client_id_(1) {}
 
 OutputConfigurator::~OutputConfigurator() {}
 
-void OutputConfigurator::SetDelegateForTesting(scoped_ptr<Delegate> delegate) {
-  delegate_ = delegate.Pass();
+void OutputConfigurator::SetNativeDisplayDelegateForTesting(
+    scoped_ptr<NativeDisplayDelegate> delegate) {
+  native_display_delegate_ = delegate.Pass();
   configure_display_ = true;
 }
 
@@ -265,8 +264,8 @@
   if (!configure_display_)
     return;
 
-  if (!delegate_)
-    delegate_.reset(new RealOutputConfiguratorDelegate());
+  if (!native_display_delegate_)
+    native_display_delegate_.reset(new NativeDisplayDelegateX11());
 
   if (!touchscreen_delegate_)
     touchscreen_delegate_.reset(new TouchscreenDelegateX11());
@@ -276,21 +275,20 @@
   if (!configure_display_)
     return;
 
-  delegate_->GrabServer();
-  delegate_->InitXRandRExtension(&xrandr_event_base_);
+  native_display_delegate_->GrabServer();
+  native_display_delegate_->InitXRandRExtension(&xrandr_event_base_);
 
   UpdateCachedOutputs();
   if (cached_outputs_.size() > 1 && background_color_argb)
-    delegate_->SetBackgroundColor(background_color_argb);
+    native_display_delegate_->SetBackgroundColor(background_color_argb);
   const OutputState new_state = ChooseOutputState(power_state_);
   const bool success = EnterStateOrFallBackToSoftwareMirroring(
       new_state, power_state_);
 
   // Force the DPMS on chrome startup as the driver doesn't always detect
   // that all displays are on when signing out.
-  delegate_->ForceDPMSOn();
-  delegate_->UngrabServer();
-  SendProjectingStateToPowerManager();
+  native_display_delegate_->ForceDPMSOn();
+  native_display_delegate_->UngrabServer();
   NotifyObservers(success, new_state);
 }
 
@@ -313,7 +311,7 @@
         HDCPState new_desired_state =
             (all_desired & OUTPUT_PROTECTION_METHOD_HDCP) ?
             HDCP_STATE_DESIRED : HDCP_STATE_UNDESIRED;
-        if (!delegate_->SetHDCPState(this_id, new_desired_state))
+        if (!native_display_delegate_->SetHDCPState(this_id, new_desired_state))
           return false;
         break;
       }
@@ -331,22 +329,6 @@
   return true;
 }
 
-void OutputConfigurator::SendProjectingStateToPowerManager() {
-  bool has_internal_output = false;
-  int connected_output_count = cached_outputs_.size() + casting_session_count_;
-  for (size_t i = 0; i < cached_outputs_.size(); ++i) {
-    if (cached_outputs_[i].type == OUTPUT_TYPE_INTERNAL) {
-      has_internal_output = true;
-      break;
-    }
-  }
-
-  // "Projecting" is defined as having more than 1 output connected while at
-  // least one of them is an internal output.
-  bool is_projecting = has_internal_output && (connected_output_count > 1);
-  delegate_->SendProjectingStateToPowerManager(is_projecting);
-}
-
 OutputConfigurator::OutputProtectionClientId
 OutputConfigurator::RegisterOutputProtectionClient() {
   if (!configure_display_)
@@ -398,7 +380,7 @@
       case OUTPUT_TYPE_DVI:
       case OUTPUT_TYPE_HDMI: {
         HDCPState state;
-        if (!delegate_->GetHDCPState(this_id, &state))
+        if (!native_display_delegate_->GetHDCPState(this_id, &state))
           return false;
         if (state == HDCP_STATE_ENABLED)
           enabled |= OUTPUT_PROTECTION_METHOD_HDCP;
@@ -485,7 +467,7 @@
   if (power_state == power_state_ && !(flags & kSetDisplayPowerForceProbe))
     return true;
 
-  delegate_->GrabServer();
+  native_display_delegate_->GrabServer();
   UpdateCachedOutputs();
 
   const OutputState new_state = ChooseOutputState(power_state);
@@ -504,10 +486,10 @@
     // Force the DPMS on since the driver doesn't always detect that it
     // should turn on. This is needed when coming back from idle suspend.
     if (success && power_state != DISPLAY_POWER_ALL_OFF)
-      delegate_->ForceDPMSOn();
+      native_display_delegate_->ForceDPMSOn();
   }
 
-  delegate_->UngrabServer();
+  native_display_delegate_->UngrabServer();
   if (attempted_change)
     NotifyObservers(success, new_state);
   return true;
@@ -527,11 +509,11 @@
     return true;
   }
 
-  delegate_->GrabServer();
+  native_display_delegate_->GrabServer();
   UpdateCachedOutputs();
   const bool success = EnterStateOrFallBackToSoftwareMirroring(
       new_state, power_state_);
-  delegate_->UngrabServer();
+  native_display_delegate_->UngrabServer();
 
   NotifyObservers(success, new_state);
   return success;
@@ -543,7 +525,7 @@
 
   if (event->type - xrandr_event_base_ == RRScreenChangeNotify) {
     VLOG(1) << "Received RRScreenChangeNotify event";
-    delegate_->UpdateXRandRConfiguration(event);
+    native_display_delegate_->UpdateXRandRConfiguration(event);
     return POST_DISPATCH_PERFORM_DEFAULT;
   }
 
@@ -611,18 +593,6 @@
 void OutputConfigurator::DidProcessEvent(const base::NativeEvent& event) {
 }
 
-void OutputConfigurator::OnCastingSessionStartedOrStopped(bool started) {
-  if (started) {
-    ++casting_session_count_;
-  } else {
-    DCHECK_GT(casting_session_count_, 0);
-    --casting_session_count_;
-    if (casting_session_count_ < 0)
-      casting_session_count_ = 0;
-  }
-  SendProjectingStateToPowerManager();
-}
-
 void OutputConfigurator::AddObserver(Observer* observer) {
   observers_.AddObserver(observer);
 }
@@ -644,7 +614,7 @@
     // We need to make sure that the monitor configuration we just did actually
     // completes before we return, because otherwise the X message could be
     // racing with the HandleSuspendReadiness message.
-    delegate_->SyncWithServer();
+    native_display_delegate_->SyncWithServer();
   }
 }
 
@@ -668,7 +638,7 @@
 }
 
 void OutputConfigurator::UpdateCachedOutputs() {
-  cached_outputs_ = delegate_->GetOutputs();
+  cached_outputs_ = native_display_delegate_->GetOutputs();
   touchscreen_delegate_->AssociateTouchscreens(&cached_outputs_);
 
   // Set |selected_mode| fields.
@@ -779,7 +749,7 @@
           !external_info.interlaced;
       if (can_fit) {
         RRMode mode = external_it->first;
-        delegate_->AddOutputMode(internal_output->output, mode);
+        native_display_delegate_->AddOutputMode(internal_output->output, mode);
         internal_output->mode_infos.insert(std::make_pair(mode, external_info));
         internal_output->mirror_mode = mode;
         external_output->mirror_mode = mode;
@@ -794,15 +764,14 @@
 void OutputConfigurator::ConfigureOutputs() {
   configure_timer_.reset();
 
-  delegate_->GrabServer();
+  native_display_delegate_->GrabServer();
   UpdateCachedOutputs();
   const OutputState new_state = ChooseOutputState(power_state_);
   const bool success = EnterStateOrFallBackToSoftwareMirroring(
       new_state, power_state_);
-  delegate_->UngrabServer();
+  native_display_delegate_->UngrabServer();
 
   NotifyObservers(success, new_state);
-  SendProjectingStateToPowerManager();
 }
 
 void OutputConfigurator::NotifyObservers(bool success,
@@ -968,14 +937,17 @@
   DCHECK_EQ(cached_outputs_.size(), updated_outputs.size());
   bool all_succeeded = true;
   if (!updated_outputs.empty()) {
-    delegate_->CreateFrameBuffer(width, height, updated_outputs);
+    native_display_delegate_->CreateFrameBuffer(width, height, updated_outputs);
     for (size_t i = 0; i < updated_outputs.size(); ++i) {
       const OutputSnapshot& output = updated_outputs[i];
       bool configure_succeeded =false;
 
       while (true) {
-        if (delegate_->ConfigureCrtc(output.crtc, output.current_mode,
-                                       output.output, output.x, output.y)) {
+        if (native_display_delegate_->ConfigureCrtc(output.crtc,
+                                                    output.current_mode,
+                                                    output.output,
+                                                    output.x,
+                                                    output.y)) {
           configure_succeeded = true;
           break;
         }
diff --git a/chromeos/display/output_configurator.h b/chromeos/display/output_configurator.h
index cee949e..7432171 100644
--- a/chromeos/display/output_configurator.h
+++ b/chromeos/display/output_configurator.h
@@ -189,10 +189,11 @@
     virtual void SetSoftwareMirroring(bool enabled) = 0;
   };
 
-  // Interface for classes that perform actions on behalf of OutputController.
-  class Delegate {
+  // Interface for classes that perform display configuration actions on behalf
+  // of OutputConfigurator.
+  class NativeDisplayDelegate {
    public:
-    virtual ~Delegate() {}
+    virtual ~NativeDisplayDelegate() {}
 
     // Initializes the XRandR extension, saving the base event ID to
     // |event_base|.
@@ -243,10 +244,6 @@
         int height,
         const std::vector<OutputConfigurator::OutputSnapshot>& outputs) = 0;
 
-    // Sends a D-Bus message to the power manager telling it that the
-    // machine is or is not projecting.
-    virtual void SendProjectingStateToPowerManager(bool projecting) = 0;
-
     // Gets HDCP state of output.
     virtual bool GetHDCPState(RROutput id, HDCPState* state) = 0;
 
@@ -349,9 +346,10 @@
     mirroring_controller_ = controller;
   }
 
-  // Replaces |delegate_| with |delegate| and sets |configure_display_| to
-  // true.  Should be called before Init().
-  void SetDelegateForTesting(scoped_ptr<Delegate> delegate);
+  // Replaces |native_display_delegate_| with |delegate| and sets
+  // |configure_display_| to true.  Should be called before Init().
+  void SetNativeDisplayDelegateForTesting(
+      scoped_ptr<NativeDisplayDelegate> delegate);
 
   void SetTouchscreenDelegateForTesting(
       scoped_ptr<TouchscreenDelegate> delegate);
@@ -395,9 +393,6 @@
       const base::NativeEvent& event) OVERRIDE;
   virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE;
 
-  // Called when a casting session is started or stopped.
-  void OnCastingSessionStartedOrStopped(bool started);
-
   void AddObserver(Observer* observer);
   void RemoveObserver(Observer* observer);
 
@@ -522,12 +517,9 @@
   // Applies output protections according to requests.
   bool ApplyProtections(const DisplayProtections& requests);
 
-  // Sends the current projecting state to power manager.
-  void SendProjectingStateToPowerManager();
-
   StateController* state_controller_;
   SoftwareMirroringController* mirroring_controller_;
-  scoped_ptr<Delegate> delegate_;
+  scoped_ptr<NativeDisplayDelegate> native_display_delegate_;
   scoped_ptr<TouchscreenDelegate> touchscreen_delegate_;
 
   // Used to enable modes which rely on panel fitting.
@@ -574,9 +566,6 @@
   // Output protection requests of each client.
   ProtectionRequests client_protection_requests_;
 
-  // Number of outstanding casting sessions.
-  int casting_session_count_;
-
   DISALLOW_COPY_AND_ASSIGN(OutputConfigurator);
 };
 
diff --git a/chromeos/display/output_configurator_unittest.cc b/chromeos/display/output_configurator_unittest.cc
index fd62430..3b53fd9 100644
--- a/chromeos/display/output_configurator_unittest.cc
+++ b/chromeos/display/output_configurator_unittest.cc
@@ -20,32 +20,33 @@
 
 namespace {
 
-// Strings returned by TestDelegate::GetActionsAndClear() to describe various
-// actions that were performed.
+// Strings returned by TestNativeDisplayDelegate::GetActionsAndClear() to
+// describe various actions that were performed.
 const char kInitXRandR[] = "init";
 const char kUpdateXRandR[] = "update";
 const char kGrab[] = "grab";
 const char kUngrab[] = "ungrab";
 const char kSync[] = "sync";
 const char kForceDPMS[] = "dpms";
-const char kProjectingOn[] = "projecting";
-const char kProjectingOff[] = "not_projecting";
 
-// String returned by TestDelegate::GetActionsAndClear() if no actions were
-// requested.
+// String returned by TestNativeDisplayDelegate::GetActionsAndClear() if no
+// actions were requested.
 const char kNoActions[] = "";
 
-// Returns a string describing a TestDelegate::SetBackgroundColor() call.
+// Returns a string describing a TestNativeDisplayDelegate::SetBackgroundColor()
+// call.
 std::string GetBackgroundAction(uint32 color_argb) {
   return base::StringPrintf("background(0x%x)", color_argb);
 }
 
-// Returns a string describing a TestDelegate::AddOutputMode() call.
+// Returns a string describing a TestNativeDisplayDelegate::AddOutputMode()
+// call.
 std::string GetAddOutputModeAction(RROutput output, RRMode mode) {
   return base::StringPrintf("add_mode(output=%lu,mode=%lu)", output, mode);
 }
 
-// Returns a string describing a TestDelegate::ConfigureCrtc() call.
+// Returns a string describing a TestNativeDisplayDelegate::ConfigureCrtc()
+// call.
 std::string GetCrtcAction(RRCrtc crtc,
                           int x,
                           int y,
@@ -55,7 +56,8 @@
                             crtc, x, y, mode, output);
 }
 
-// Returns a string describing a TestDelegate::CreateFramebuffer() call.
+// Returns a string describing a TestNativeDisplayDelegate::CreateFramebuffer()
+// call.
 std::string GetFramebufferAction(int width,
                                  int height,
                                  RRCrtc crtc1,
@@ -65,7 +67,7 @@
       width, height, crtc1, crtc2);
 }
 
-// Returns a string describing a TestDelegate::ConfigureCTM() call.
+// Returns a string describing a TestNativeDisplayDelegate::ConfigureCTM() call.
 std::string GetCTMAction(
     int device_id,
     const OutputConfigurator::CoordinateTransformation& ctm) {
@@ -73,14 +75,14 @@
       ctm.x_scale, ctm.x_offset, ctm.y_scale, ctm.y_offset);
 }
 
-// Returns a string describing a TestDelegate::SetHDCPState() call.
+// Returns a string describing a TestNativeDisplayDelegate::SetHDCPState() call.
 std::string GetSetHDCPStateAction(RROutput id, HDCPState state) {
   return base::StringPrintf("set_hdcp(id=%lu,state=%d)", id, state);
 }
 
 // Joins a sequence of strings describing actions (e.g. kScreenDim) such
 // that they can be compared against a string returned by
-// TestDelegate::GetActionsAndClear().  The list of actions must be
+// ActionLogger::GetActionsAndClear().  The list of actions must be
 // terminated by a NULL pointer.
 std::string JoinActions(const char* action, ...) {
   std::string actions;
@@ -152,16 +154,17 @@
   DISALLOW_COPY_AND_ASSIGN(TestTouchscreenDelegate);
 };
 
-class TestDelegate : public OutputConfigurator::Delegate {
+class TestNativeDisplayDelegate
+    : public OutputConfigurator::NativeDisplayDelegate {
  public:
   static const int kXRandREventBase = 10;
 
   // Ownership of |log| remains with the caller.
-  explicit TestDelegate(ActionLogger* log)
+  explicit TestNativeDisplayDelegate(ActionLogger* log)
       : max_configurable_pixels_(0),
         hdcp_state_(HDCP_STATE_UNDESIRED),
         log_(log) {}
-  virtual ~TestDelegate() {}
+  virtual ~TestNativeDisplayDelegate() {}
 
   const std::vector<OutputConfigurator::OutputSnapshot>& outputs() const {
     return outputs_;
@@ -232,10 +235,6 @@
                              outputs.size() >= 1 ? outputs[0].crtc : 0,
                              outputs.size() >= 2 ? outputs[1].crtc : 0));
   }
-  virtual void SendProjectingStateToPowerManager(bool projecting) OVERRIDE {
-    log_->AppendAction(projecting ? kProjectingOn : kProjectingOff);
-  }
-
   virtual bool GetHDCPState(RROutput id, HDCPState* state) OVERRIDE {
     *state = hdcp_state_;
     return true;
@@ -271,7 +270,7 @@
 
   ActionLogger* log_;  // Not owned.
 
-  DISALLOW_COPY_AND_ASSIGN(TestDelegate);
+  DISALLOW_COPY_AND_ASSIGN(TestNativeDisplayDelegate);
 };
 
 class TestObserver : public OutputConfigurator::Observer {
@@ -383,15 +382,17 @@
 
   OutputConfiguratorTest()
       : observer_(&configurator_),
-        test_api_(&configurator_, TestDelegate::kXRandREventBase) {}
+        test_api_(&configurator_, TestNativeDisplayDelegate::kXRandREventBase) {
+  }
   virtual ~OutputConfiguratorTest() {}
 
   virtual void SetUp() OVERRIDE {
     log_.reset(new ActionLogger());
 
-    delegate_ = new TestDelegate(log_.get());
-    configurator_.SetDelegateForTesting(
-        scoped_ptr<OutputConfigurator::Delegate>(delegate_));
+    native_display_delegate_ = new TestNativeDisplayDelegate(log_.get());
+    configurator_.SetNativeDisplayDelegateForTesting(
+        scoped_ptr<OutputConfigurator::NativeDisplayDelegate>(
+            native_display_delegate_));
 
     touchscreen_delegate_ = new TestTouchscreenDelegate(log_.get());
     configurator_.SetTouchscreenDelegateForTesting(
@@ -438,7 +439,8 @@
   }
 
  protected:
-  // Configures |delegate_| to return the first |num_outputs| entries from
+  // Configures |native_display_delegate_| to return the first |num_outputs|
+  // entries from
   // |outputs_|. If |send_events| is true, also sends screen-change and
   // output-change events to |configurator_| and triggers the configure
   // timeout if one was scheduled.
@@ -447,7 +449,7 @@
     std::vector<OutputConfigurator::OutputSnapshot> outputs;
     for (size_t i = 0; i < num_outputs; ++i)
       outputs.push_back(outputs_[i]);
-    delegate_->set_outputs(outputs);
+    native_display_delegate_->set_outputs(outputs);
 
     if (send_events) {
       test_api_.SendScreenChangeEvent();
@@ -479,7 +481,6 @@
                 .c_str(),
             kForceDPMS,
             kUngrab,
-            kProjectingOff,
             NULL),
         log_->GetActionsAndClear());
   }
@@ -490,7 +491,7 @@
   OutputConfigurator configurator_;
   TestObserver observer_;
   scoped_ptr<ActionLogger> log_;
-  TestDelegate* delegate_;  // not owned
+  TestNativeDisplayDelegate* native_display_delegate_;  // not owned
   TestTouchscreenDelegate* touchscreen_delegate_;  // not owned
   OutputConfigurator::TestApi test_api_;
 
@@ -595,7 +596,6 @@
                         kBigModeId,
                         outputs_[1].output).c_str(),
           kUngrab,
-          kProjectingOn,
           NULL),
       log_->GetActionsAndClear());
   EXPECT_FALSE(mirroring_controller_.software_mirroring_enabled());
@@ -632,7 +632,6 @@
           GetCrtcAction(
               outputs_[0].crtc, 0, 0, kSmallModeId, outputs_[0].output).c_str(),
           kUngrab,
-          kProjectingOff,
           NULL),
       log_->GetActionsAndClear());
   EXPECT_FALSE(mirroring_controller_.software_mirroring_enabled());
@@ -657,7 +656,6 @@
                         kBigModeId,
                         outputs_[1].output).c_str(),
           kUngrab,
-          kProjectingOn,
           NULL),
       log_->GetActionsAndClear());
   EXPECT_FALSE(mirroring_controller_.software_mirroring_enabled());
@@ -696,7 +694,6 @@
           GetCrtcAction(
               outputs_[0].crtc, 0, 0, kSmallModeId, outputs_[0].output).c_str(),
           kUngrab,
-          kProjectingOff,
           NULL),
       log_->GetActionsAndClear());
   EXPECT_FALSE(mirroring_controller_.software_mirroring_enabled());
@@ -722,7 +719,6 @@
           GetCrtcAction(
               outputs_[1].crtc, 0, 0, kSmallModeId, outputs_[1].output).c_str(),
           kUngrab,
-          kProjectingOn,
           NULL),
       log_->GetActionsAndClear());
   EXPECT_FALSE(mirroring_controller_.software_mirroring_enabled());
@@ -815,7 +811,6 @@
                         kBigModeId,
                         outputs_[1].output).c_str(),
           kUngrab,
-          kProjectingOn,
           NULL),
       log_->GetActionsAndClear());
   EXPECT_EQ(STATE_DUAL_EXTENDED, configurator_.output_state());
@@ -894,53 +889,6 @@
   EXPECT_EQ(1, observer_.num_changes());
 }
 
-TEST_F(OutputConfiguratorTest, Casting) {
-  InitWithSingleOutput();
-
-  // Notify configurator that casting session is started.
-  configurator_.OnCastingSessionStartedOrStopped(true);
-  EXPECT_EQ(kProjectingOn, log_->GetActionsAndClear());
-
-  // Verify that the configurator keeps a count of active casting sessions
-  // instead of treating it as a single global state.
-  configurator_.OnCastingSessionStartedOrStopped(true);
-  EXPECT_EQ(kProjectingOn, log_->GetActionsAndClear());
-  configurator_.OnCastingSessionStartedOrStopped(false);
-  EXPECT_EQ(kProjectingOn, log_->GetActionsAndClear());
-
-  // Turn all displays off and check that projecting is not turned off.
-  configurator_.SetDisplayPower(DISPLAY_POWER_ALL_OFF,
-                                OutputConfigurator::kSetDisplayPowerNoFlags);
-  EXPECT_EQ(
-      JoinActions(
-          kGrab,
-          GetFramebufferAction(
-              kSmallModeWidth, kSmallModeHeight, outputs_[0].crtc, 0).c_str(),
-          GetCrtcAction(outputs_[0].crtc, 0, 0, 0, outputs_[0].output).c_str(),
-          kUngrab,
-          NULL),
-      log_->GetActionsAndClear());
-
-  // Turn all displays back on.
-  configurator_.SetDisplayPower(DISPLAY_POWER_ALL_ON,
-                                OutputConfigurator::kSetDisplayPowerNoFlags);
-  EXPECT_EQ(
-      JoinActions(
-          kGrab,
-          GetFramebufferAction(
-              kSmallModeWidth, kSmallModeHeight, outputs_[0].crtc, 0).c_str(),
-          GetCrtcAction(
-              outputs_[0].crtc, 0, 0, kSmallModeId, outputs_[0].output).c_str(),
-          kForceDPMS,
-          kUngrab,
-          NULL),
-      log_->GetActionsAndClear());
-
-  // Notify configurator that casting session is ended.
-  configurator_.OnCastingSessionStartedOrStopped(false);
-  EXPECT_EQ(kProjectingOff, log_->GetActionsAndClear());
-}
-
 TEST_F(OutputConfiguratorTest, SuspendAndResume) {
   InitWithSingleOutput();
 
@@ -1020,7 +968,6 @@
           GetCrtcAction(
               outputs_[1].crtc, 0, 0, kSmallModeId, outputs_[1].output).c_str(),
           kUngrab,
-          kProjectingOn,
           NULL),
       log_->GetActionsAndClear());
 
@@ -1064,8 +1011,7 @@
   configurator_.Init(false);
   EXPECT_EQ(kNoActions, log_->GetActionsAndClear());
   configurator_.Start(0);
-  EXPECT_EQ(JoinActions(
-                kGrab, kInitXRandR, kForceDPMS, kUngrab, kProjectingOff, NULL),
+  EXPECT_EQ(JoinActions(kGrab, kInitXRandR, kForceDPMS, kUngrab, NULL),
             log_->GetActionsAndClear());
 
   // Not much should happen when the display power state is changed while
@@ -1090,7 +1036,6 @@
           GetCrtcAction(outputs_[0].crtc, 0, 0, kBigModeId, outputs_[0].output)
               .c_str(),
           kUngrab,
-          kProjectingOff,
           NULL),
       log_->GetActionsAndClear());
 }
@@ -1117,7 +1062,6 @@
               outputs_[1].crtc, 0, 0, kSmallModeId, outputs_[1].output).c_str(),
           kForceDPMS,
           kUngrab,
-          kProjectingOn,
           NULL),
       log_->GetActionsAndClear());
 }
@@ -1208,7 +1152,6 @@
           GetCrtcAction(
               outputs_[1].crtc, 0, 0, kSmallModeId, outputs_[1].output).c_str(),
           kUngrab,
-          kProjectingOn,
           NULL),
       log_->GetActionsAndClear());
 
@@ -1229,7 +1172,6 @@
           GetCrtcAction(
               outputs_[1].crtc, 0, 0, kSmallModeId, outputs_[1].output).c_str(),
           kUngrab,
-          kProjectingOn,
           NULL),
       log_->GetActionsAndClear());
 
@@ -1244,7 +1186,6 @@
           GetCrtcAction(
               outputs_[0].crtc, 0, 0, kSmallModeId, outputs_[0].output).c_str(),
           kUngrab,
-          kProjectingOff,
           NULL),
       log_->GetActionsAndClear());
 
@@ -1257,7 +1198,7 @@
 
   // Lower the limit for which the delegate will succeed, which should result
   // in the second output sticking with its native mode.
-  delegate_->set_max_configurable_pixels(1);
+  native_display_delegate_->set_max_configurable_pixels(1);
   UpdateOutputs(2, true);
   EXPECT_EQ(
       JoinActions(
@@ -1289,13 +1230,12 @@
                         kSmallModeId,
                         outputs_[1].output).c_str(),
           kUngrab,
-          kProjectingOn,
           NULL),
       log_->GetActionsAndClear());
 
   // A change event reporting a mode change on the second output should
   // trigger another reconfigure.
-  delegate_->set_max_configurable_pixels(0);
+  native_display_delegate_->set_max_configurable_pixels(0);
   test_api_.SendOutputChangeEvent(
       outputs_[1].output, outputs_[1].crtc, outputs_[1].mirror_mode, true);
   EXPECT_TRUE(test_api_.TriggerConfigureTimeout());
@@ -1311,7 +1251,6 @@
           GetCrtcAction(
               outputs_[1].crtc, 0, 0, kSmallModeId, outputs_[1].output).c_str(),
           kUngrab,
-          kProjectingOn,
           NULL),
       log_->GetActionsAndClear());
 }
@@ -1370,7 +1309,6 @@
               outputs_[1].crtc, 0, 0, kSmallModeId, outputs_[1].output).c_str(),
           kForceDPMS,
           kUngrab,
-          kProjectingOn,
           NULL),
       log_->GetActionsAndClear());
 
@@ -1435,7 +1373,7 @@
             log_->GetActionsAndClear());
 
   // Enable protection.
-  delegate_->set_hdcp_state(HDCP_STATE_ENABLED);
+  native_display_delegate_->set_hdcp_state(HDCP_STATE_ENABLED);
   EXPECT_TRUE(configurator_.QueryOutputProtectionStatus(id,
                                                         outputs_[1].display_id,
                                                         &link_mask,
@@ -1471,7 +1409,7 @@
   EXPECT_EQ(
       GetSetHDCPStateAction(outputs_[1].output, HDCP_STATE_DESIRED).c_str(),
       log_->GetActionsAndClear());
-  delegate_->set_hdcp_state(HDCP_STATE_ENABLED);
+  native_display_delegate_->set_hdcp_state(HDCP_STATE_ENABLED);
 
   uint32_t link_mask = 0;
   uint32_t protection_mask = 0;
@@ -1572,7 +1510,7 @@
   // First test simply fails in STATE_SINGLE mode.   This is probably
   // unrealistic but the want to make sure any assumptions don't
   // creep in.
-  delegate_->set_max_configurable_pixels(
+  native_display_delegate_->set_max_configurable_pixels(
       outputs_[0].mode_infos[kFirstMode + 2].width *
       outputs_[0].mode_infos[kFirstMode + 2].height);
   state_controller_.set_state(STATE_SINGLE);
@@ -1592,13 +1530,12 @@
               outputs_[0].crtc, 0, 0, kFirstMode + 2, outputs_[0].output)
               .c_str(),
           kUngrab,
-          kProjectingOff,
           NULL),
       log_->GetActionsAndClear());
 
   // This test should attempt to configure a mirror mode that will not succeed
   // and should end up in extended mode.
-  delegate_->set_max_configurable_pixels(
+  native_display_delegate_->set_max_configurable_pixels(
       outputs_[0].mode_infos[kFirstMode + 3].width *
       outputs_[0].mode_infos[kFirstMode + 3].height);
   state_controller_.set_state(STATE_DUAL_MIRROR);
@@ -1653,7 +1590,6 @@
                         kFirstMode + 3,
                         outputs_[1].output).c_str(),
           kUngrab,
-          kProjectingOn,
           NULL),
       log_->GetActionsAndClear());
 }