Use GrResourceCache2 to service content key lookups

BUG=skia:2889

Review URL: https://codereview.chromium.org/707493002
diff --git a/src/gpu/GrResourceCache2.cpp b/src/gpu/GrResourceCache2.cpp
index 6bc23a3..65e522a 100644
--- a/src/gpu/GrResourceCache2.cpp
+++ b/src/gpu/GrResourceCache2.cpp
@@ -9,7 +9,6 @@
 
 #include "GrResourceCache2.h"
 #include "GrGpuResource.h"  
-#include "SkRefCnt.h"
 
 GrResourceCache2::~GrResourceCache2() {
     this->releaseAll();
@@ -22,6 +21,8 @@
     fResources.addToHead(resource);
     ++fCount;
     if (!resource->getScratchKey().isNullScratch()) {
+        // TODO(bsalomon): Make this assertion possible.
+        // SkASSERT(!resource->isWrapped());
         fScratchMap.insert(resource->getScratchKey(), resource);
     }
 }
@@ -32,6 +33,9 @@
     if (!resource->getScratchKey().isNullScratch()) {
         fScratchMap.remove(resource->getScratchKey(), resource);
     }
+    if (const GrResourceKey* contentKey = resource->getContentKey()) {
+        fContentHash.remove(*contentKey);
+    }
     --fCount;
 }
 
@@ -43,6 +47,7 @@
         SkASSERT(head != fResources.head());
     }
     SkASSERT(!fScratchMap.count());
+    SkASSERT(!fContentHash.count());
     SkASSERT(!fCount);
 }
 
@@ -89,3 +94,25 @@
     }
     return SkSafeRef(fScratchMap.find(scratchKey, AvailableForScratchUse(false)));
 }
+
+void GrResourceCache2::willRemoveContentKey(const GrGpuResource* resource) {
+    SkASSERT(resource);
+    SkASSERT(resource->getContentKey());
+    SkDEBUGCODE(GrGpuResource* res = fContentHash.find(*resource->getContentKey()));
+    SkASSERT(res == resource);
+
+    fContentHash.remove(*resource->getContentKey());
+}
+
+bool GrResourceCache2::didAddContentKey(GrGpuResource* resource) {
+    SkASSERT(resource);
+    SkASSERT(resource->getContentKey());
+
+    GrGpuResource* res = fContentHash.find(*resource->getContentKey());
+    if (NULL != res) {
+        return false;
+    }
+
+    fContentHash.add(resource);
+    return true;
+}