Esempio n. 1
0
// Called when the a Read of the response body is completed after an
// IO_PENDING status from a Read() call.
// The data read is filled into the buffer which the caller passed
// to Read() previously.
//
// If an error occurred, request->status() will contain the error,
// and bytes read will be -1.
void WebRequest::OnReadCompleted(net::URLRequest* request, int bytesRead)
{
    ASSERT(m_loadState == Response || m_loadState == GotData, "OnReadCompleted in state other than RESPONSE and GOTDATA");

    if (request->status().is_success()) {
        //SAMSUNG_CHANGES >>
        if(m_rssSniffingEnabled) 
        {
            if( m_ShouldSniffFeed) { 
                std::string  currentMimeType, newMimeType;
                bool sniffResult = false;
                GURL sniffURL(m_url);
                m_request->GetMimeType(&currentMimeType);
                sniffResult = net::SniffMimeType(m_networkBuffer->data(), bytesRead, sniffURL,currentMimeType, &newMimeType);
                m_ShouldSniffFeed = false;
                if(TYPE_ATOM == newMimeType ||TYPE_RDF  == newMimeType || TYPE_RSS == newMimeType)
                    m_webResponse-> setMimeType(TYPE_MAYBE_FEED );
					
                    m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(
                            m_urlLoader.get(), &WebUrlLoaderClient::didReceiveResponse, m_webResponse.release()));
	
            }
        }
        //SAMSUNG_CHANGES <<
        m_loadState = GotData;
        m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(
                m_urlLoader.get(), &WebUrlLoaderClient::didReceiveData, m_networkBuffer, bytesRead));
        m_networkBuffer = 0;

        // Get the rest of the data
        startReading();
    } else {
        finish(false);
    }
}
Esempio n. 2
0
void WebRequest::startReading()
{
#if !_USE_SAMSUNG_PERFORMANCE_IMPROVE_
    ASSERT(m_networkBuffer == 0, "startReading called with a nonzero buffer");
#endif
    ASSERT(m_isPaused == 0, "startReading called in paused state");
    ASSERT(m_loadState == Response || m_loadState == GotData, "StartReading in state other than RESPONSE and GOTDATA");
    if (m_loadState > GotData) // We have been cancelled between reads
        return;

    if (m_wantToPause) {
        m_isPaused = true;
        return;
    }

    int bytesRead = 0;

    if (!read(&bytesRead)) {
        if (m_request && m_request->status().is_io_pending())
            return; // Wait for OnReadCompleted()
        return finish(false);
    }
    //SAMSUNG_CHANGES >>
    if(m_rssSniffingEnabled) 	
    {
        if( m_ShouldSniffFeed) { 
            std::string currentMimeType, newMimeType;
            m_request->GetMimeType(&currentMimeType);
            bool sniffResult = false;
            GURL sniffURL(m_url);
            sniffResult = net::SniffMimeType(m_networkBuffer->data(), bytesRead, sniffURL,currentMimeType, &newMimeType);
            m_ShouldSniffFeed = false;
            if(TYPE_ATOM == newMimeType ||TYPE_RDF  == newMimeType || TYPE_RSS == newMimeType)
                m_webResponse-> setMimeType(TYPE_MAYBE_FEED );
                m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(
                        m_urlLoader.get(), &WebUrlLoaderClient::didReceiveResponse, m_webResponse.release()));
        }
    }
    //SAMSUNG_CHANGES <<
    // bytesRead == 0 indicates finished
    if (!bytesRead)
        return finish(true);

    m_loadState = GotData;
    // Read ok, forward buffer to webcore
#if _USE_SAMSUNG_PERFORMANCE_IMPROVE_
    // SAMSUNG CHANGE : reduce events in main thread >>
    m_BytesInBuffer += bytesRead;
    sendDataReceivedEvent(false);
    // SAMSUNG CHANGE : reduce events in main thread <<
#else
    m_urlLoader->maybeCallOnMainThread(NewRunnableMethod(m_urlLoader.get(), &WebUrlLoaderClient::didReceiveData, m_networkBuffer, bytesRead));
    m_networkBuffer = 0;
#endif
    MessageLoop::current()->PostTask(FROM_HERE, m_runnableFactory.NewRunnableMethod(&WebRequest::startReading));
}