Move GpuMemoryManager::ClientState structure to its own class.

Also clean up initialization path so that the GpuMemoryManager returns
a GpuMemoryManagerClientState, and destroying that structure deletes
the client.

BUG=164947


Review URL: https://chromiumcodereview.appspot.com/11571075

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174591 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/common/gpu/gpu_command_buffer_stub.cc b/content/common/gpu/gpu_command_buffer_stub.cc
index 0eadd90..3a0d799 100644
--- a/content/common/gpu/gpu_command_buffer_stub.cc
+++ b/content/common/gpu/gpu_command_buffer_stub.cc
@@ -47,23 +47,21 @@
 class GpuCommandBufferMemoryTracker : public gpu::gles2::MemoryTracker {
  public:
   GpuCommandBufferMemoryTracker(GpuChannel* channel) :
-    gpu_memory_manager_tracking_group_(new GpuMemoryTrackingGroup(
-        channel->renderer_pid(),
-        this,
-        channel->gpu_channel_manager()->gpu_memory_manager())) {
+      tracking_group_(channel->gpu_channel_manager()->gpu_memory_manager()->
+          CreateTrackingGroup(channel->renderer_pid(), this)) {
   }
 
   void TrackMemoryAllocatedChange(size_t old_size,
                                   size_t new_size,
                                   gpu::gles2::MemoryTracker::Pool pool) {
-    gpu_memory_manager_tracking_group_->TrackMemoryAllocatedChange(
+    tracking_group_->TrackMemoryAllocatedChange(
         old_size, new_size, pool);
   }
 
  private:
   ~GpuCommandBufferMemoryTracker() {
   }
-  scoped_ptr<GpuMemoryTrackingGroup> gpu_memory_manager_tracking_group_;
+  scoped_ptr<GpuMemoryTrackingGroup> tracking_group_;
 
   DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferMemoryTracker);
 };
@@ -302,7 +300,7 @@
         active_url_));
   }
 
-  GetMemoryManager()->RemoveClient(this);
+  memory_manager_client_state_.reset();
 
   while (!sync_points_.empty())
     OnRetireSyncPoint(sync_points_.front());
@@ -721,8 +719,8 @@
 
 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) {
   TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetSurfaceVisible");
-  GetMemoryManager()->
-      SetClientVisible(this, visible);
+  if (memory_manager_client_state_.get())
+    memory_manager_client_state_->SetVisible(visible);
 }
 
 void GpuCommandBufferStub::OnDiscardBackbuffer() {
@@ -800,8 +798,8 @@
   TRACE_EVENT0(
       "gpu",
       "GpuCommandBufferStub::OnReceivedClientManagedMemoryStats");
-  GetMemoryManager()->
-      SetClientManagedMemoryStats(this, stats);
+  if (memory_manager_client_state_.get())
+    memory_manager_client_state_->SetManagedMemoryStats(stats);
 }
 
 void GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback(
@@ -809,10 +807,14 @@
   TRACE_EVENT0(
       "gpu",
       "GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback");
-  if (has_callback)
-    GetMemoryManager()->AddClient(this, surface_id_ != 0, true);
-  else
-    GetMemoryManager()->RemoveClient(this);
+  if (has_callback) {
+    if (!memory_manager_client_state_.get()) {
+      memory_manager_client_state_.reset(GetMemoryManager()->CreateClientState(
+          this, surface_id_ != 0, true));
+    }
+  } else {
+    memory_manager_client_state_.reset();
+  }
 }
 
 void GpuCommandBufferStub::SendConsoleMessage(